Skip to content
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

Fail validation if AidaDb does not contain StateHashes #769

Merged
merged 3 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 1 addition & 14 deletions executor/extension/validator/state_hash_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ func (e *stateHashValidator[T]) PostBlock(state executor.State[T], ctx *executor
return err
}

// is stat hash present?
nilHash := common.Hash{}
if want == nilHash {
return nil
}

got := ctx.State.GetHash()
if want != got {
return fmt.Errorf("unexpected hash for Live block %d\nwanted %v\n got %v", state.Block, want, got)
Expand Down Expand Up @@ -108,12 +102,6 @@ func (e *stateHashValidator[T]) checkArchiveHashes(state state.StateDB) error {
return err
}

// is state hash present?
nilHash := common.Hash{}
if want == nilHash {
return nil
}

archive, err := state.GetArchiveState(cur)
if err != nil {
return err
Expand All @@ -135,8 +123,7 @@ func (e *stateHashValidator[T]) getStateHash(blockNumber int) (common.Hash, erro
want, err := e.hashProvider.GetStateHash(blockNumber)
if err != nil {
if errors.Is(err, leveldb.ErrNotFound) {
e.log.Warningf("State hash for block %v is not present in the db", blockNumber)
return common.Hash{}, nil
return common.Hash{}, fmt.Errorf("state hash for block %v is not present in the db", blockNumber)
}
return common.Hash{}, fmt.Errorf("cannot get state hash for block %v; %v", blockNumber, err)
}
Expand Down
14 changes: 10 additions & 4 deletions executor/extension/validator/state_hash_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestStateHashValidator_NotActiveIfNotEnabledInConfig(t *testing.T) {
}
}

func TestStateHashValidator_DoesNotFailIfHashIsNotFoundInAidaDb(t *testing.T) {
func TestStateHashValidator_FailsIfHashIsNotFoundInAidaDb(t *testing.T) {
ctrl := gomock.NewController(t)
log := logger.NewMockLogger(ctrl)
db := state.NewMockStateDB(ctrl)
Expand All @@ -40,7 +40,6 @@ func TestStateHashValidator_DoesNotFailIfHashIsNotFoundInAidaDb(t *testing.T) {

gomock.InOrder(
hashProvider.EXPECT().GetStateHash(blockNumber).Return(common.Hash{}, leveldb.ErrNotFound),
log.EXPECT().Warningf("State hash for block %v is not present in the db", blockNumber),
)

cfg := &utils.Config{}
Expand All @@ -49,8 +48,15 @@ func TestStateHashValidator_DoesNotFailIfHashIsNotFoundInAidaDb(t *testing.T) {

ctx := &executor.Context{State: db}

if err := ext.PostBlock(executor.State[any]{Block: blockNumber}, ctx); err != nil {
t.Errorf("failed to check hash: %v", err)
err := ext.PostBlock(executor.State[any]{Block: blockNumber}, ctx)
if err == nil {
t.Error("post block must return error")
}

wantedErr := fmt.Sprintf("state hash for block %v is not present in the db", blockNumber)

if strings.Compare(err.Error(), wantedErr) != 0 {
t.Fatalf("unexpected error\nwant: %v\ngot: %v", wantedErr, err.Error())
}

if err := ext.PostRun(executor.State[any]{Block: 1}, ctx, nil); err != nil {
Expand Down