-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
687 populate grandpa and babe states from runtime #691
687 populate grandpa and babe states from runtime #691
Conversation
…) method - Introduced `ServiceConsensusState` interface to define the initializeFromRuntime() method for RoundState and EpochState as requiring runtime data. - Implemented initializeFromRuntime() - Integrated these state initializations within FullSyncMachine to ensure proper synchronization during node startup.
…Runtime() method" This reverts commit 7a25cf6.
…mRuntime() method" This reverts commit 29d1682.
…teDataFromRuntime() in ServiceConsensusState interface.
… of consensus states from db.
Quality Gate passedIssues Measures |
return trieAccessor | ||
.findStorageValue(Nibbles.fromBytes(":code".getBytes())) | ||
.map(wasm -> buildRuntime(wasm, trieAccessor)) | ||
.orElseThrow(() -> new RuntimeException("Runtime code not found in the trie")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change this to one of our custom exceptions or create 1 if there isn't a good match. We want to generally avoid using generic exceptions such as this one.
@@ -58,4 +59,7 @@ public interface Runtime { | |||
void persistsChanges(); | |||
|
|||
void close(); | |||
|
|||
List<Authority> getGrandpaApiGrandpaAuthorities(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is the name of the API method, but I'd go for something like getGrandpaApiAuthorities
or getGrandpaAuthorities
. Preferably the first one so it's similar to the babe API one.
|
||
@Override | ||
public List<Authority> getGrandpaApiGrandpaAuthorities() { | ||
return ScaleUtils.Decode.decode(call(RuntimeEndpoint.GRANDPA_API_GRANDPA_AUTHORITIES), new ListReader<>(new AuthorityReader())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Split this into two lines as it is longer than the suggested by Intellij.
public void populateDataFromRuntime(Runtime runtime) { | ||
this.authorities = runtime.getGrandpaApiGrandpaAuthorities(); | ||
this.setId = BigInteger.ZERO; | ||
this.roundNumber = BigInteger.ZERO; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per spec the round at initialization should be 1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not strictly related to this PR, but we need something like a base state to hold all the states. This way, we can have a centralized place to keep them and avoid injecting them as beans all over the place. The constructors are getting ridiculously large.
@@ -67,6 +68,8 @@ public class FullSyncMachine { | |||
private final TrieStorage trieStorage = AppBean.getBean(TrieStorage.class); | |||
private final RuntimeBuilder runtimeBuilder = AppBean.getBean(RuntimeBuilder.class); | |||
private final EpochState epochState = AppBean.getBean(EpochState.class); | |||
private final RoundState roundState = AppBean.getBean(RoundState.class); | |||
private final GenesisBlockHash genesisBlockHash = AppBean.getBean(GenesisBlockHash.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need the GenesisBlockHash
here. We have SyncState
which holds the last finalized block number. We can compare it with 0 (genesis block number) and avoid this bean.
# Description See the following PRs: #688 #701 #691 --------- Co-authored-by: Hristiyan Mitov <[email protected]> Co-authored-by: Hristiyan Mitov <[email protected]>
Description
feat: Add ServiceConsensusState interface with populateFromRuntime() method
ServiceConsensusState
interface to define the initializeFromRuntime() method for RoundState and EpochState as requiring runtime data.Fixes Add functionality to populate grandpa and babe states from runtime. #687