Skip to content

Commit

Permalink
Merge branch 'master' into add-readmode-inboxreader
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuacolvin0 authored Feb 7, 2024
2 parents 2be83d1 + a7026a7 commit 7646d73
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 22 deletions.
45 changes: 39 additions & 6 deletions arbnode/sync_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,27 @@ func NewSyncMonitor(config *SyncMonitorConfig) *SyncMonitor {
}

type SyncMonitorConfig struct {
BlockBuildLag uint64 `koanf:"block-build-lag"`
BlockBuildSequencerInboxLag uint64 `koanf:"block-build-sequencer-inbox-lag"`
CoordinatorMsgLag uint64 `koanf:"coordinator-msg-lag"`
BlockBuildLag uint64 `koanf:"block-build-lag"`
BlockBuildSequencerInboxLag uint64 `koanf:"block-build-sequencer-inbox-lag"`
CoordinatorMsgLag uint64 `koanf:"coordinator-msg-lag"`
SafeBlockWaitForBlockValidator bool `koanf:"safe-block-wait-for-block-validator"`
FinalizedBlockWaitForBlockValidator bool `koanf:"finalized-block-wait-for-block-validator"`
}

var DefaultSyncMonitorConfig = SyncMonitorConfig{
BlockBuildLag: 20,
BlockBuildSequencerInboxLag: 0,
CoordinatorMsgLag: 15,
BlockBuildLag: 20,
BlockBuildSequencerInboxLag: 0,
CoordinatorMsgLag: 15,
SafeBlockWaitForBlockValidator: false,
FinalizedBlockWaitForBlockValidator: false,
}

func SyncMonitorConfigAddOptions(prefix string, f *flag.FlagSet) {
f.Uint64(prefix+".block-build-lag", DefaultSyncMonitorConfig.BlockBuildLag, "allowed lag between messages read and blocks built")
f.Uint64(prefix+".block-build-sequencer-inbox-lag", DefaultSyncMonitorConfig.BlockBuildSequencerInboxLag, "allowed lag between messages read from sequencer inbox and blocks built")
f.Uint64(prefix+".coordinator-msg-lag", DefaultSyncMonitorConfig.CoordinatorMsgLag, "allowed lag between local and remote messages")
f.Bool(prefix+".safe-block-wait-for-block-validator", DefaultSyncMonitorConfig.SafeBlockWaitForBlockValidator, "wait for block validator to complete before returning safe block number")
f.Bool(prefix+".finalized-block-wait-for-block-validator", DefaultSyncMonitorConfig.FinalizedBlockWaitForBlockValidator, "wait for block validator to complete before returning finalized block number")
}

func (s *SyncMonitor) Initialize(inboxReader *InboxReader, txStreamer *TransactionStreamer, coordinator *SeqCoordinator, exec execution.FullExecutionClient) {
Expand Down Expand Up @@ -153,10 +159,27 @@ func (s *SyncMonitor) SafeBlockNumber(ctx context.Context) (uint64, error) {
if err != nil {
return 0, err
}
// If SafeBlockWaitForBlockValidator is true, we want to wait for the block validator to finish
if s.config.SafeBlockWaitForBlockValidator {
latestValidatedCount, err := s.getLatestValidatedCount()
if err != nil {
return 0, err
}
if msg > latestValidatedCount {
msg = latestValidatedCount
}
}
block := s.exec.MessageIndexToBlockNumber(msg - 1)
return block, nil
}

func (s *SyncMonitor) getLatestValidatedCount() (arbutil.MessageIndex, error) {
if s.txStreamer.validator == nil {
return 0, errors.New("validator not set up")
}
return s.txStreamer.validator.GetValidated(), nil
}

func (s *SyncMonitor) FinalizedBlockNumber(ctx context.Context) (uint64, error) {
if s.inboxReader == nil || !s.initialized {
return 0, errors.New("not set up for safeblock")
Expand All @@ -165,6 +188,16 @@ func (s *SyncMonitor) FinalizedBlockNumber(ctx context.Context) (uint64, error)
if err != nil {
return 0, err
}
// If FinalizedBlockWaitForBlockValidator is true, we want to wait for the block validator to finish
if s.config.FinalizedBlockWaitForBlockValidator {
latestValidatedCount, err := s.getLatestValidatedCount()
if err != nil {
return 0, err
}
if msg > latestValidatedCount {
msg = latestValidatedCount
}
}
block := s.exec.MessageIndexToBlockNumber(msg - 1)
return block, nil
}
Expand Down
48 changes: 32 additions & 16 deletions precompiles/precompile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
package precompiles

import (
"fmt"
"math/big"
"os"
"testing"

"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/log"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -176,22 +179,35 @@ func TestEventCosts(t *testing.T) {
}
}

type FatalBurner struct {
t *testing.T
count uint64
gasLeft uint64
}

func NewFatalBurner(t *testing.T, limit uint64) FatalBurner {
return FatalBurner{t, 0, limit}
}
func TestPrecompilesPerArbosVersion(t *testing.T) {
// Set up a logger in case log.Crit is called by Precompiles()
glogger := log.NewGlogHandler(log.StreamHandler(os.Stderr, log.TerminalFormat(false)))
glogger.Verbosity(log.LvlWarn)
log.Root().SetHandler(glogger)

expectedNewMethodsPerArbosVersion := map[uint64]int{
0: 89,
5: 3,
10: 2,
11: 4,
20: 8,
}

precompiles := Precompiles()
newMethodsPerArbosVersion := make(map[uint64]int)
for _, precompile := range precompiles {
for _, method := range precompile.Precompile().methods {
newMethodsPerArbosVersion[method.arbosVersion]++
}
}

func (burner FatalBurner) Burn(amount uint64) error {
burner.t.Helper()
burner.count += 1
if burner.gasLeft < amount {
Fail(burner.t, "out of gas after", burner.count, "burns")
if len(expectedNewMethodsPerArbosVersion) != len(newMethodsPerArbosVersion) {
t.Errorf("expected %v ArbOS versions with new precompile methods but got %v", len(expectedNewMethodsPerArbosVersion), len(newMethodsPerArbosVersion))
}
for version, count := range newMethodsPerArbosVersion {
fmt.Printf("got %v version count %v\n", version, count)
if expectedNewMethodsPerArbosVersion[version] != count {
t.Errorf("expected %v new precompile methods for ArbOS version %v but got %v", expectedNewMethodsPerArbosVersion[version], version, count)
}
}
burner.gasLeft -= amount
return nil
}
6 changes: 6 additions & 0 deletions staker/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1208,3 +1208,9 @@ func (v *BlockValidator) WaitForPos(t *testing.T, ctx context.Context, pos arbut
}
}
}

func (v *BlockValidator) GetValidated() arbutil.MessageIndex {
v.reorgMutex.RLock()
defer v.reorgMutex.RUnlock()
return v.validated()
}

0 comments on commit 7646d73

Please sign in to comment.