Skip to content

Commit

Permalink
stub out preimage fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
nomaxg committed Nov 8, 2023
1 parent d1636c8 commit e935fb8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions staker/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ type BlockValidatorConfig struct {
PendingUpgradeModuleRoot string `koanf:"pending-upgrade-module-root"` // TODO(magic) requires StatelessBlockValidator recreation on hot reload
FailureIsFatal bool `koanf:"failure-is-fatal" reload:"hot"`
Dangerous BlockValidatorDangerousConfig `koanf:"dangerous"`
// Espresso specific flags
Espresso bool `koanf:"espresso"`
}

func (c *BlockValidatorConfig) Validate() error {
Expand All @@ -107,6 +109,7 @@ func BlockValidatorConfigAddOptions(prefix string, f *flag.FlagSet) {
f.String(prefix+".current-module-root", DefaultBlockValidatorConfig.CurrentModuleRoot, "current wasm module root ('current' read from chain, 'latest' from machines/latest dir, or provide hash)")
f.String(prefix+".pending-upgrade-module-root", DefaultBlockValidatorConfig.PendingUpgradeModuleRoot, "pending upgrade wasm module root to additionally validate (hash, 'latest' or empty)")
f.Bool(prefix+".failure-is-fatal", DefaultBlockValidatorConfig.FailureIsFatal, "failing a validation is treated as a fatal error")
f.Bool(prefix+".espresso", DefaultBlockValidatorConfig.Espresso, "if true, hotshot header preimages will be added to validation entries to verify that transactions have been sequenced by espresso")
BlockValidatorDangerousConfigAddOptions(prefix+".dangerous", f)
}

Expand Down
10 changes: 10 additions & 0 deletions staker/stateless_block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"sync"
"testing"

"github.com/offchainlabs/nitro/espresso"
"github.com/offchainlabs/nitro/execution"
"github.com/offchainlabs/nitro/util/rpcclient"
"github.com/offchainlabs/nitro/validator/server_api"
Expand Down Expand Up @@ -69,6 +70,7 @@ type TransactionStreamerInterface interface {

type InboxReaderInterface interface {
GetSequencerMessageBytes(ctx context.Context, seqNum uint64) ([]byte, error)
FetchHotShotCommitment(blockHeight uint64) (espresso.Commitment, error)
}

type L1ReaderInterface interface {
Expand Down Expand Up @@ -259,6 +261,7 @@ func (v *StatelessBlockValidator) GetModuleRootsToValidate() []common.Hash {
}

func (v *StatelessBlockValidator) ValidationEntryRecord(ctx context.Context, e *validationEntry) error {
usingEspresso := v.config.Espresso
if e.Stage != ReadyForRecord {
return fmt.Errorf("validation entry should be ReadyForRecord, is: %v", e.Stage)
}
Expand Down Expand Up @@ -305,6 +308,13 @@ func (v *StatelessBlockValidator) ValidationEntryRecord(ctx context.Context, e *
return err
}
}
if usingEspresso {
_, err := v.inboxReader.FetchHotShotCommitment(batch.Number)
if err != nil {
return fmt.Errorf("failed to fetch hotshot commitment for batch number %d", batch.Number)
}
// TODO construct preimage here and add to validation entry
}
}

e.msg = nil // no longer needed
Expand Down

0 comments on commit e935fb8

Please sign in to comment.