Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d06c288
WIP on node interface seggregation
yarikbratashchuk Nov 27, 2024
3fce7ae
Fix compile errors
yarikbratashchuk Dec 3, 2024
fb1e4ec
Remove rpc server from rollkit
yarikbratashchuk Dec 10, 2024
12f7e65
Fix lint errors
yarikbratashchuk Dec 12, 2024
d3df482
Fix some more lint issues
yarikbratashchuk Dec 12, 2024
1704717
Comment out unreachable code
yarikbratashchuk Dec 12, 2024
75872c2
Handle CI mode for node
yarikbratashchuk Dec 12, 2024
13cc399
Fix full node
yarikbratashchuk Dec 16, 2024
503c98b
Docs gen
yarikbratashchuk Dec 16, 2024
0fb08e1
Fix lint errors
yarikbratashchuk Dec 17, 2024
00ad30d
Fix vulns found by dependabot
yarikbratashchuk Dec 17, 2024
b7d5ec0
Fix markdown lint
yarikbratashchuk Dec 17, 2024
a2c4b28
Fixes for lint fixes
yarikbratashchuk Dec 17, 2024
975a289
Remove rpc-equivalency-coverage
yarikbratashchuk Dec 17, 2024
0abc30d
Fix serialization tests
yarikbratashchuk Dec 17, 2024
590b8a6
Remove proxy client creator
yarikbratashchuk Jan 7, 2025
a8529b5
Fix linting issues
yarikbratashchuk Jan 7, 2025
6468fc5
Fix tests, typos
yarikbratashchuk Jan 9, 2025
5bb907a
Start mock executor on rollkit start
yarikbratashchuk Jan 9, 2025
efa6ad2
Comment out publish block test
yarikbratashchuk Jan 9, 2025
5a9cb2d
Comment out node failing tests for now, will uncomment and fix them o…
yarikbratashchuk Jan 9, 2025
f6b391d
Revorking tests, commenting out execution bits
yarikbratashchuk Jan 15, 2025
c93989b
WIP: revorking tests
yarikbratashchuk Jan 16, 2025
fa42d1a
Remove tendermint types from state proto to make restarting work
yarikbratashchuk Jan 17, 2025
ca9bcfe
Fix linting issues
yarikbratashchuk Jan 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove tendermint types from state proto to make restarting work
  • Loading branch information
yarikbratashchuk committed Jan 17, 2025
commit fa42d1aa5cdabcee7243f1a4a54c2edf3dd1a277
23 changes: 15 additions & 8 deletions block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"sync/atomic"
"time"

"github.com/cometbft/cometbft/crypto/merkle"
cmbytes "github.com/cometbft/cometbft/libs/bytes"
cmstate "github.com/cometbft/cometbft/proto/tendermint/state"

Expand Down Expand Up @@ -170,15 +171,18 @@ type RollkitGenesis struct {
}

// getInitialState tries to load lastState from Store, and if it's not available it reads GenesisDoc.
func getInitialState(ctx context.Context, genesis *RollkitGenesis, store store.Store, exec execution.Executor) (types.State, error) {
func getInitialState(ctx context.Context, genesis *RollkitGenesis, store store.Store, exec execution.Executor, logger log.Logger) (types.State, error) {
// Load the state from store.
s, err := store.GetState(context.Background())

if errors.Is(err, ds.ErrNotFound) {
logger.Info("No state found in store, initializing new state")

// If the user is starting a fresh chain (or hard-forking), we assume the stored state is empty.
// TODO(tzdybal): handle max bytes
stateRoot, _, err := exec.InitChain(ctx, genesis.GenesisTime, genesis.InitialHeight, genesis.ChainID)
if err != nil {
logger.Error("error while initializing chain", "error", err)
return types.State{}, err
}

Expand All @@ -202,6 +206,7 @@ func getInitialState(ctx context.Context, genesis *RollkitGenesis, store store.S
}
return s, nil
} else if err != nil {
logger.Error("error while getting state", "error", err)
return types.State{}, err
} else {
// Perform a sanity-check to stop the user from
Expand Down Expand Up @@ -232,8 +237,9 @@ func NewManager(
seqMetrics *Metrics,
execMetrics *state.Metrics,
) (*Manager, error) {
s, err := getInitialState(ctx, genesis, store, exec)
s, err := getInitialState(ctx, genesis, store, exec, logger)
if err != nil {
logger.Error("error while getting initial state", "error", err)
return nil, err
}
//set block height in store
Expand Down Expand Up @@ -274,6 +280,7 @@ func NewManager(

isProposer, err := isProposer(proposerKey, s)
if err != nil {
logger.Error("error while checking if proposer", "error", err)
return nil, err
}

Expand Down Expand Up @@ -1068,7 +1075,7 @@ func (m *Manager) publishBlock(ctx context.Context) error {
}
lastHeader, lastData, err := m.store.GetBlockData(ctx, height)
if err != nil {
return fmt.Errorf("error while loading last block: %w", err)
return fmt.Errorf("error while loading last block at height %d: %w", height, err)
}
lastHeaderHash = lastHeader.Hash()
lastDataHash = lastData.Hash()
Expand Down Expand Up @@ -1165,9 +1172,9 @@ func (m *Manager) publishBlock(ctx context.Context) error {
return err
}

if err := m.processVoteExtension(ctx, header, data, newHeight); err != nil {
return err
}
//if err := m.processVoteExtension(ctx, header, data, newHeight); err != nil {
// return err
//}

// set the signature to current block's signed header
header.Signature = signature
Expand Down Expand Up @@ -1215,6 +1222,7 @@ func (m *Manager) publishBlock(ctx context.Context) error {
newState.DAHeight = atomic.LoadUint64(&m.daHeight)
// After this call m.lastState is the NEW state returned from ApplyBlock
// updateState also commits the DB tx
m.logger.Debug("updating state", "newState", newState)
err = m.updateState(ctx, newState)
if err != nil {
return err
Expand Down Expand Up @@ -1428,6 +1436,7 @@ func (m *Manager) exponentialBackoff(backoff time.Duration) time.Duration {

// Updates the state stored in manager's store along the manager's lastState
func (m *Manager) updateState(ctx context.Context, s types.State) error {
m.logger.Debug("updating state", "newState", s)
m.lastStateMtx.Lock()
defer m.lastStateMtx.Unlock()
err := m.store.UpdateState(ctx, s)
Expand Down Expand Up @@ -1546,7 +1555,6 @@ func (m *Manager) nextState(state types.State, header *types.SignedHeader, state
return s, nil
}

/*
func updateState(s *types.State, res *abci.ResponseInitChain) error {
// If the app did not return an app hash, we keep the one set from the genesis doc in
// the state. We don't set appHash since we don't want the genesis doc app hash
Expand Down Expand Up @@ -1600,4 +1608,3 @@ func updateState(s *types.State, res *abci.ResponseInitChain) error {

return nil
}
*/
9 changes: 6 additions & 3 deletions block/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ func TestInitialStateClean(t *testing.T) {
InitialHeight: 1,
ProposerAddress: genesisDoc.Validators[0].Address.Bytes(),
}
logger := test.NewLogger(t)
es, _ := store.NewDefaultInMemoryKVStore()
emptyStore := store.New(es)
s, err := getInitialState(context.TODO(), genesis, emptyStore, execTest.NewDummyExecutor())
s, err := getInitialState(context.TODO(), genesis, emptyStore, execTest.NewDummyExecutor(), logger)
require.NoError(err)
require.Equal(s.LastBlockHeight, genesis.InitialHeight-1)
require.Equal(genesis.InitialHeight, s.InitialHeight)
Expand Down Expand Up @@ -115,7 +116,8 @@ func TestInitialStateStored(t *testing.T) {
store := store.New(es)
err := store.UpdateState(ctx, sampleState)
require.NoError(err)
s, err := getInitialState(context.TODO(), genesis, store, execTest.NewDummyExecutor())
logger := test.NewLogger(t)
s, err := getInitialState(context.TODO(), genesis, store, execTest.NewDummyExecutor(), logger)
require.NoError(err)
require.Equal(s.LastBlockHeight, uint64(100))
require.Equal(s.InitialHeight, uint64(1))
Expand Down Expand Up @@ -169,6 +171,7 @@ func TestHandleEmptyDataHash(t *testing.T) {

func TestInitialStateUnexpectedHigherGenesis(t *testing.T) {
require := require.New(t)
logger := test.NewLogger(t)
genesisDoc, _ := types.GetGenesisWithPrivkey(types.DefaultSigningKeyType, "TestInitialStateUnexpectedHigherGenesis")
valset := types.GetRandomValidatorSet()
genesis := &RollkitGenesis{
Expand All @@ -190,7 +193,7 @@ func TestInitialStateUnexpectedHigherGenesis(t *testing.T) {
store := store.New(es)
err := store.UpdateState(ctx, sampleState)
require.NoError(err)
_, err = getInitialState(context.TODO(), genesis, store, execTest.NewDummyExecutor())
_, err = getInitialState(context.TODO(), genesis, store, execTest.NewDummyExecutor(), logger)
require.EqualError(err, "genesis.InitialHeight (2) is greater than last stored state's LastBlockHeight (0)")
}

Expand Down
7 changes: 7 additions & 0 deletions cmd/rollkit/commands/run_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (

execGRPC "github.com/rollkit/go-execution/proxy/grpc"
execTest "github.com/rollkit/go-execution/test"
execTypes "github.com/rollkit/go-execution/types"
pb "github.com/rollkit/go-execution/types/pb/execution"
)

Expand Down Expand Up @@ -296,6 +297,12 @@ func tryStartMockSequencerServerGRPC(listenAddress string, rollupId string) (*gr
// tryStartMockExecutorServerGRPC will try and start a mock gRPC executor server
func tryStartMockExecutorServerGRPC(listenAddress string) (*grpc.Server, error) {
dummyExec := execTest.NewDummyExecutor()

dummyExec.InjectTx(execTypes.Tx{1, 2, 3})
dummyExec.InjectTx(execTypes.Tx{4, 5, 6})
dummyExec.InjectTx(execTypes.Tx{7, 8, 9})
dummyExec.InjectTx(execTypes.Tx{10, 11, 12})

execServer := execGRPC.NewServer(dummyExec, nil)
server := grpc.NewServer()
pb.RegisterExecutionServiceServer(server, execServer)
Expand Down
2 changes: 2 additions & 0 deletions node/full.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ func initBlockManager(signingKey crypto.PrivKey, nodeConfig config.NodeConfig, g
return nil, fmt.Errorf("error while initializing executor: %w", err)
}

logger.Debug("Proposer address", "address", genesis.Validators[0].Address.Bytes())

rollGen := &block.RollkitGenesis{
GenesisTime: genesis.GenesisTime,
InitialHeight: uint64(genesis.InitialHeight),
Expand Down
10 changes: 5 additions & 5 deletions proto/rollkit/state.proto
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ message State {
// Note that if s.LastBlockHeight causes a valset change,
// we set s.LastHeightValidatorsChanged = s.LastBlockHeight + 1 + 1
// Extra +1 due to nextValSet delay.
tendermint.types.ValidatorSet next_validators = 7;
tendermint.types.ValidatorSet validators = 8;
tendermint.types.ValidatorSet last_validators = 9;
int64 last_height_validators_changed = 10;
//tendermint.types.ValidatorSet next_validators = 7;
//tendermint.types.ValidatorSet validators = 8;
//tendermint.types.ValidatorSet last_validators = 9;
//int64 last_height_validators_changed = 10;
uint64 da_height = 11 [(gogoproto.customname) = "DAHeight"];

tendermint.types.ConsensusParams consensus_params = 12 [(gogoproto.nullable) = false];
uint64 last_height_consensus_params_changed = 13;
//uint64 last_height_consensus_params_changed = 13;

bytes last_results_hash = 14;

Expand Down
Loading