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
b270ecb9
Commit
b270ecb9
authored
5 months ago
by
bgallois
Committed by
Hugo Trentesaux
5 months ago
Browse files
Options
Downloads
Patches
Plain Diff
inherent data provider cannot fail
parent
f4f23dfd
No related branches found
No related tags found
1 merge request
!294
Fix #264: Distance inherent data provider should not fail
Pipeline
#39248
skipped
Changes
2
Pipelines
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
client/distance/src/lib.rs
+64
-52
64 additions, 52 deletions
client/distance/src/lib.rs
node/src/service.rs
+2
-2
2 additions, 2 deletions
node/src/service.rs
with
66 additions
and
54 deletions
client/distance/src/lib.rs
+
64
−
52
View file @
b270ecb9
...
@@ -59,37 +59,35 @@ pub fn create_distance_inherent_data_provider<B, C, Backend>(
...
@@ -59,37 +59,35 @@ pub fn create_distance_inherent_data_provider<B, C, Backend>(
parent
:
B
::
Hash
,
parent
:
B
::
Hash
,
distance_dir
:
PathBuf
,
distance_dir
:
PathBuf
,
owner_keys
:
&
[
sp_core
::
sr25519
::
Public
],
owner_keys
:
&
[
sp_core
::
sr25519
::
Public
],
)
->
Result
<
sp_distance
::
InherentDataProvider
<
IdtyIndex
>
,
sc_client_api
::
blockchain
::
Error
>
)
->
sp_distance
::
InherentDataProvider
<
IdtyIndex
>
where
where
B
:
BlockT
,
B
:
BlockT
,
C
:
ProvideUncles
<
B
>
+
StorageProvider
<
B
,
Backend
>
,
C
:
ProvideUncles
<
B
>
+
StorageProvider
<
B
,
Backend
>
,
Backend
:
sc_client_api
::
Backend
<
B
>
,
Backend
:
sc_client_api
::
Backend
<
B
>
,
IdtyIndex
:
Decode
+
Encode
+
PartialEq
+
TypeInfo
,
IdtyIndex
:
Decode
+
Encode
+
PartialEq
+
TypeInfo
,
{
{
// Retrieve the period_index from storage. If storage is inaccessible or the data is corrupted,
// Retrieve the period_index from storage.
// return the appropriate error.
let
period_index
=
client
let
period_index
=
client
.storage
(
.storage
(
parent
,
parent
,
&
StorageKey
(
&
StorageKey
(
frame_support
::
storage
::
storage_prefix
(
b"Distance"
,
b"CurrentPeriodIndex"
)
.to_vec
(),
frame_support
::
storage
::
storage_prefix
(
b"Distance"
,
b"CurrentPeriodIndex"
)
.to_vec
(),
),
),
)
?
)
.map_or_else
(
.ok
()
||
{
.flatten
()
Err
(
sc_client_api
::
blockchain
::
Error
::
Storage
(
.and_then
(|
raw
|
u32
::
decode
(
&
mut
&
raw
.0
[
..
])
.ok
());
"CurrentPeriodIndex value not found"
.to_string
(),
))
// Return early if the storage is inaccessible or the data is corrupted.
},
let
period_index
=
match
period_index
{
|
raw
|
{
Some
(
index
)
=>
index
,
u32
::
decode
(
&
mut
&
raw
.0
[
..
])
None
=>
{
.map_err
(|
e
|
sc_client_api
::
blockchain
::
Error
::
from_state
(
Box
::
new
(
e
)))
log
::
error!
(
"🧙 [distance inherent] PeriodIndex decoding failed."
);
},
return
sp_distance
::
InherentDataProvider
::
<
IdtyIndex
>
::
new
(
None
);
)
?
;
}
};
// Retrieve the published_results from storage.
// Retrieve the published_results from storage.
// Return an error if the storage is inaccessible.
// If accessible, continue execution. If None, it means there are no published_results at this block.
let
published_results
=
client
let
published_results
=
client
.storage
(
.storage
(
parent
,
parent
,
...
@@ -105,13 +103,22 @@ where
...
@@ -105,13 +103,22 @@ where
)
)
.to_vec
(),
.to_vec
(),
),
),
)
?
)
.ok
()
.flatten
()
.and_then
(|
raw
|
{
.and_then
(|
raw
|
{
pallet_distance
::
EvaluationPool
::
<
AccountId32
,
IdtyIndex
>
::
decode
(
&
mut
&
raw
.0
[
..
])
.ok
()
pallet_distance
::
EvaluationPool
::
<
AccountId32
,
IdtyIndex
>
::
decode
(
&
mut
&
raw
.0
[
..
])
.ok
()
});
});
// Have we already published a result for this period?
// Return early if the storage is inaccessible or the data is corrupted.
if
let
Some
(
results
)
=
published_results
{
let
published_results
=
match
published_results
{
Some
(
published_results
)
=>
published_results
,
None
=>
{
log
::
info!
(
"🧙 [distance inherent] No published result at this block."
);
return
sp_distance
::
InherentDataProvider
::
<
IdtyIndex
>
::
new
(
None
);
}
};
// 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
mut
local_account
=
None
;
let
mut
local_account
=
None
;
for
key
in
owner_keys
{
for
key
in
owner_keys
{
...
@@ -123,29 +130,34 @@ where
...
@@ -123,29 +130,34 @@ where
storage_key
.extend_from_slice
(
&
sp_core
::
twox_64
(
&
item_key
));
storage_key
.extend_from_slice
(
&
sp_core
::
twox_64
(
&
item_key
));
storage_key
.extend_from_slice
(
&
item_key
);
storage_key
.extend_from_slice
(
&
item_key
);
if
let
Some
(
raw_data
)
=
client
.storage
(
parent
,
&
StorageKey
(
storage_key
))
?
{
if
let
Some
(
raw_data
)
=
client
.storage
(
parent
,
&
StorageKey
(
storage_key
))
.ok
()
.flatten
()
{
if
let
Ok
(
key_owner
)
=
AccountId32
::
decode
(
&
mut
&
raw_data
.0
[
..
])
{
if
let
Ok
(
key_owner
)
=
AccountId32
::
decode
(
&
mut
&
raw_data
.0
[
..
])
{
local_account
=
Some
(
key_owner
);
local_account
=
Some
(
key_owner
);
break
;
break
;
}
else
{
}
else
{
log
::
warn!
(
"🧙 [distance
oracle
] Cannot decode key owner value"
);
log
::
warn!
(
"🧙 [distance
inherent
] Cannot decode key owner value"
);
}
}
}
}
}
}
// Have we already published a result for this period?
if
let
Some
(
local_account
)
=
local_account
{
if
let
Some
(
local_account
)
=
local_account
{
if
results
.evaluators
.contains
(
&
local_account
)
{
if
published_
results
.evaluators
.contains
(
&
local_account
)
{
log
::
debug!
(
"🧙 [distance
oracle
] Already published a result for this period"
);
log
::
debug!
(
"🧙 [distance
inherent
] Already published a result for this period"
);
return
Ok
(
sp_distance
::
InherentDataProvider
::
<
IdtyIndex
>
::
new
(
None
)
)
;
return
sp_distance
::
InherentDataProvider
::
<
IdtyIndex
>
::
new
(
None
);
}
}
}
else
{
}
else
{
log
::
error!
(
"🧙 [distance oracle] Cannot find our BABE owner key"
);
log
::
error!
(
"🧙 [distance inherent] Cannot find our BABE owner key"
);
return
Ok
(
sp_distance
::
InherentDataProvider
::
<
IdtyIndex
>
::
new
(
None
));
return
sp_distance
::
InherentDataProvider
::
<
IdtyIndex
>
::
new
(
None
);
}
}
}
// Read evaluation result from file, if it exists
// Read evaluation result from file, if it exists
log
::
debug!
(
log
::
debug!
(
"🧙 [distance
oracle
] Reading evaluation result from file {:?}"
,
"🧙 [distance
inherent
] Reading evaluation result from file {:?}"
,
distance_dir
.clone
()
.join
(
period_index
.to_string
())
distance_dir
.clone
()
.join
(
period_index
.to_string
())
);
);
let
evaluation_result
=
match
std
::
fs
::
read
(
let
evaluation_result
=
match
std
::
fs
::
read
(
...
@@ -155,20 +167,20 @@ where
...
@@ -155,20 +167,20 @@ where
Err
(
e
)
=>
{
Err
(
e
)
=>
{
match
e
.kind
()
{
match
e
.kind
()
{
std
::
io
::
ErrorKind
::
NotFound
=>
{
std
::
io
::
ErrorKind
::
NotFound
=>
{
log
::
debug!
(
"🧙 [distance
oracle
] Evaluation result file not found. Please ensure that the oracle version matches {}"
,
VERSION_PREFIX
);
log
::
debug!
(
"🧙 [distance
inherent
] Evaluation result file not found. Please ensure that the oracle version matches {}"
,
VERSION_PREFIX
);
}
}
_
=>
{
_
=>
{
log
::
error!
(
log
::
error!
(
"🧙 [distance
oracle
] Cannot read distance evaluation result file: {e:?}"
"🧙 [distance
inherent
] Cannot read distance evaluation result file: {e:?}"
);
);
}
}
}
}
return
Ok
(
sp_distance
::
InherentDataProvider
::
<
IdtyIndex
>
::
new
(
None
)
)
;
return
sp_distance
::
InherentDataProvider
::
<
IdtyIndex
>
::
new
(
None
);
}
}
};
};
log
::
info!
(
"🧙 [distance
oracle
] Providing evaluation result"
);
log
::
info!
(
"🧙 [distance
inherent
] Providing evaluation result"
);
Ok
(
sp_distance
::
InherentDataProvider
::
<
IdtyIndex
>
::
new
(
Some
(
sp_distance
::
InherentDataProvider
::
<
IdtyIndex
>
::
new
(
Some
(
sp_distance
::
ComputationResult
::
decode
(
&
mut
evaluation_result
.as_slice
())
.unwrap
(),
sp_distance
::
ComputationResult
::
decode
(
&
mut
evaluation_result
.as_slice
())
.unwrap
(),
))
)
))
}
}
This diff is collapsed.
Click to expand it.
node/src/service.rs
+
2
−
2
View file @
b270ecb9
...
@@ -503,7 +503,7 @@ where
...
@@ -503,7 +503,7 @@ where
FullBackend
,
FullBackend
,
>
(
>
(
&*
client
,
parent
,
distance_dir
,
&
babe_owner_keys
.clone
()
&*
client
,
parent
,
distance_dir
,
&
babe_owner_keys
.clone
()
)
?
;
);
Ok
((
timestamp
,
babe
,
distance
))
Ok
((
timestamp
,
babe
,
distance
))
}
}
},
},
...
@@ -549,7 +549,7 @@ where
...
@@ -549,7 +549,7 @@ where
FullBackend
,
FullBackend
,
>
(
>
(
&*
client
,
parent
,
distance_dir
,
&
babe_owner_keys
.clone
()
&*
client
,
parent
,
distance_dir
,
&
babe_owner_keys
.clone
()
)
?
;
);
Ok
((
slot
,
timestamp
,
storage_proof
,
distance
))
Ok
((
slot
,
timestamp
,
storage_proof
,
distance
))
}
}
...
...
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