Skip to content

Commit

Permalink
roothash: Store past runtime state and I/O roots in consensus state
Browse files Browse the repository at this point in the history
  • Loading branch information
abukosek committed Sep 26, 2023
1 parent 647d533 commit fc4365b
Show file tree
Hide file tree
Showing 10 changed files with 724 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changelog/5359.breaking.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
roothash: Store past runtime state and I/O roots in consensus state

A new roothash consensus parameter was added (`MaxPastRootsStored`),
which enables storing runtime state and I/O roots for the past
`MaxPastRootsStored` rounds in the consensus state.
This enables easier cross-runtime communication.
2 changes: 2 additions & 0 deletions go/consensus/cometbft/apps/roothash/liveness_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ func TestLivenessProcessing(t *testing.T) {

// Initialize roothash state.
roothashState := roothashState.NewMutableState(ctx.State())
err = roothashState.SetConsensusParameters(ctx, &roothash.ConsensusParameters{})
require.NoError(err, "SetConsensusParameters")
blk := block.NewGenesisBlock(runtime.ID, 0)
rtState := &roothash.RuntimeState{
Runtime: &runtime,
Expand Down
13 changes: 13 additions & 0 deletions go/consensus/cometbft/apps/roothash/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ func (app *rootHashApplication) changeParameters(ctx *api.Context, msg interface
if err != nil {
return nil, fmt.Errorf("roothash: failed to load consensus parameters: %w", err)
}
var needToDeletePastRoots bool
if changes.MaxPastRootsStored != nil && *changes.MaxPastRootsStored < params.MaxPastRootsStored {
// If we've reduced the number of past roots stored, we need to delete
// the excess when applying the new parameters.
needToDeletePastRoots = true
}
if err = changes.SanityCheck(); err != nil {
return nil, fmt.Errorf("roothash: failed to validate consensus parameter changes: %w", err)
}
Expand All @@ -143,6 +149,13 @@ func (app *rootHashApplication) changeParameters(ctx *api.Context, msg interface

// Apply changes.
if apply {
if needToDeletePastRoots {
err = state.ShrinkPastRoots(ctx, params.MaxPastRootsStored)
if err != nil {
return nil, fmt.Errorf("roothash: failed to shrink past stored roots: %w", err)
}
}

if err = state.SetConsensusParameters(ctx, params); err != nil {
return nil, fmt.Errorf("roothash: failed to update consensus parameters: %w", err)
}
Expand Down
Loading

0 comments on commit fc4365b

Please sign in to comment.