feat(store/v2): add WorkingHash (#20706)
This commit is contained in:
@@ -237,6 +237,8 @@ func (c *Consensus[T]) InitChain(ctx context.Context, req *abciproto.InitChainRe
|
||||
|
||||
// store chainID to be used later on in execution
|
||||
c.chainID = req.ChainId
|
||||
// TODO: check if we need to load the config from genesis.json or config.toml
|
||||
c.cfg.InitialHeight = uint64(req.InitialHeight)
|
||||
|
||||
// On a new chain, we consider the init chain block height as 0, even though
|
||||
// req.InitialHeight is 1 by default.
|
||||
@@ -281,6 +283,11 @@ func (c *Consensus[T]) InitChain(ctx context.Context, req *abciproto.InitChainRe
|
||||
|
||||
validatorUpdates := intoABCIValidatorUpdates(blockresponse.ValidatorUpdates)
|
||||
|
||||
// set the initial version of the store
|
||||
if err := c.store.SetInitialVersion(uint64(req.InitialHeight)); err != nil {
|
||||
return nil, fmt.Errorf("failed to set initial version: %w", err)
|
||||
}
|
||||
|
||||
stateChanges, err := genesisState.GetStateChanges()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -288,9 +295,9 @@ func (c *Consensus[T]) InitChain(ctx context.Context, req *abciproto.InitChainRe
|
||||
cs := &store.Changeset{
|
||||
Changes: stateChanges,
|
||||
}
|
||||
stateRoot, err := c.store.Commit(cs)
|
||||
stateRoot, err := c.store.WorkingHash(cs)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to commit the changeset: %w", err)
|
||||
return nil, fmt.Errorf("unable to write the changeset: %w", err)
|
||||
}
|
||||
|
||||
return &abci.InitChainResponse{
|
||||
@@ -414,6 +421,21 @@ func (c *Consensus[T]) FinalizeBlock(
|
||||
// LastCommit: sdktypes.ToSDKCommitInfo(req.DecidedLastCommit),
|
||||
// })
|
||||
|
||||
// we don't need to deliver the block in the genesis block
|
||||
if req.Height == int64(c.cfg.InitialHeight) {
|
||||
appHash, err := c.store.Commit(store.NewChangeset())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to commit the changeset: %w", err)
|
||||
}
|
||||
c.lastCommittedBlock.Store(&BlockData{
|
||||
Height: req.Height,
|
||||
Hash: appHash,
|
||||
})
|
||||
return &abciproto.FinalizeBlockResponse{
|
||||
AppHash: appHash,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// TODO(tip): can we expect some txs to not decode? if so, what we do in this case? this does not seem to be the case,
|
||||
// considering that prepare and process always decode txs, assuming they're the ones providing txs we should never
|
||||
// have a tx that fails decoding.
|
||||
|
||||
@@ -14,6 +14,13 @@ type Store interface {
|
||||
// associated with it.
|
||||
StateLatest() (uint64, store.ReaderMap, error)
|
||||
|
||||
// SetInitialVersion sets the initial version of the store.
|
||||
SetInitialVersion(uint64) error
|
||||
|
||||
// WorkingHash writes the provided changeset to the state and returns
|
||||
// the working hash of the state.
|
||||
WorkingHash(*store.Changeset) (store.Hash, error)
|
||||
|
||||
// Commit commits the provided changeset and returns
|
||||
// the new state root of the state.
|
||||
Commit(*store.Changeset) (store.Hash, error)
|
||||
|
||||
Reference in New Issue
Block a user