Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Duniter v2S
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
rust
Duniter v2S
Commits
407b1d15
Commit
407b1d15
authored
5 months ago
by
Pascal Engélibert
Browse files
Options
Downloads
Patches
Plain Diff
Avoid decoding storage by hand
parent
4f0f3825
No related branches found
No related tags found
1 merge request
!291
Fix distance evaluation client
Pipeline
#38679
waiting for manual action
Stage: quality
Stage: build
Stage: tests
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
client/distance/src/lib.rs
+23
-24
23 additions, 24 deletions
client/distance/src/lib.rs
with
23 additions
and
24 deletions
client/distance/src/lib.rs
+
23
−
24
View file @
407b1d15
...
@@ -87,34 +87,33 @@ where
...
@@ -87,34 +87,33 @@ where
// Have we already published a result for this period?
// Have we already published a result for this period?
if
let
Some
(
results
)
=
published_results
{
if
let
Some
(
results
)
=
published_results
{
// Find the account associated with the BABE key that is in our owner keys.
// Find the account associated with the BABE key that is in our owner keys.
let
Some
((
_key
,
local_account
))
=
client
let
mut
local_account
=
None
;
.storage_pairs
(
for
key
in
owner_keys
{
parent
,
// Session::KeyOwner is StorageMap<_, Twox64Concat, (KeyTypeId, Vec<u8>), AccountId32, OptionQuery>
Some
(
&
StorageKey
(
// Slices (variable length) and array (fixed length) are encoded differently, so the `.as_slice()` is needed
frame_support
::
storage
::
storage_prefix
(
b"Session"
,
b"KeyOwner"
)
.to_vec
(),
let
item_key
=
(
sp_runtime
::
KeyTypeId
(
*
b"babe"
),
key
.0
.as_slice
())
.encode
();
)),
let
mut
storage_key
=
None
,
frame_support
::
storage
::
storage_prefix
(
b"Session"
,
b"KeyOwner"
)
.to_vec
();
)
?
storage_key
.extend_from_slice
(
&
sp_core
::
twox_64
(
&
item_key
));
.filter_map
(|(
raw_key
,
raw_data
)|
{
storage_key
.extend_from_slice
(
&
item_key
);
if
&
raw_key
.0
[
40
..
44
]
==
b"babe"
{
Some
((
if
let
Some
(
raw_data
)
=
client
.storage
(
parent
,
&
StorageKey
(
storage_key
))
?
{
sp_core
::
sr25519
::
Public
::
from_raw
(
if
let
Ok
(
key_owner
)
=
AccountId32
::
decode
(
&
mut
&
raw_data
.0
[
..
])
{
raw_key
.0
[
45
..
45
+
32
]
.try_into
()
.unwrap
(),
local_account
=
Some
(
key_owner
);
),
break
;
AccountId32
::
decode
(
&
mut
&
raw_data
.0
[
..
])
.ok
()
?
,
))
}
else
{
}
else
{
None
log
::
warn!
(
"🧙 [distance oracle] Cannot decode key owner value"
);
}
}
})
}
.find
(|(
key
,
_data
)|
owner_keys
.contains
(
key
))
}
else
{
if
let
Some
(
local_account
)
=
local_account
{
if
results
.evaluators
.contains
(
&
local_account
)
{
log
::
debug!
(
"🧙 [distance oracle] Already published a result for this period"
);
return
Ok
(
sp_distance
::
InherentDataProvider
::
<
IdtyIndex
>
::
new
(
None
));
}
}
else
{
log
::
error!
(
"🧙 [distance oracle] Cannot find our BABE owner key"
);
log
::
error!
(
"🧙 [distance oracle] Cannot find our BABE owner key"
);
return
Ok
(
sp_distance
::
InherentDataProvider
::
<
IdtyIndex
>
::
new
(
None
));
return
Ok
(
sp_distance
::
InherentDataProvider
::
<
IdtyIndex
>
::
new
(
None
));
};
if
results
.evaluators
.contains
(
&
local_account
)
{
log
::
debug!
(
"🧙 [distance oracle] Already published a result for this period"
);
return
Ok
(
sp_distance
::
InherentDataProvider
::
<
IdtyIndex
>
::
new
(
None
));
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment