Skip to content

Commit

Permalink
Remove unnecessary flags
Browse files Browse the repository at this point in the history
  • Loading branch information
ImJeremyHe committed Nov 21, 2024
1 parent 5742b95 commit 6862859
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 98 deletions.
20 changes: 15 additions & 5 deletions arbnode/batch_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,13 @@ type BatchPosterConfig struct {
gasRefunder common.Address
l1BlockBound l1BlockBound
// Espresso specific flags
LightClientAddress string `koanf:"light-client-address"`
HotShotUrl string `koanf:"hotshot-url"`
UserDataAttestationFile string `koanf:"user-data-attestation-file"`
QuoteFile string `koanf:"quote-file"`
UseEscapeHatch bool `koanf:"use-escape-hatch"`
LightClientAddress string `koanf:"light-client-address"`
HotShotUrl string `koanf:"hotshot-url"`
UserDataAttestationFile string `koanf:"user-data-attestation-file"`
QuoteFile string `koanf:"quote-file"`
UseEscapeHatch bool `koanf:"use-escape-hatch"`
EspressoTxnsPollingInterval time.Duration `koanf:"espresso-txns-polling-interval"`
EspressoSwitchDelayThreshold uint64 `koanf:"espresso-switch-delay-threshold"`
}

func (c *BatchPosterConfig) Validate() error {
Expand Down Expand Up @@ -244,6 +246,8 @@ func BatchPosterConfigAddOptions(prefix string, f *pflag.FlagSet) {
f.String(prefix+".user-data-attestation-file", DefaultBatchPosterConfig.UserDataAttestationFile, "specifies the file containing the user data attestation")
f.String(prefix+".quote-file", DefaultBatchPosterConfig.QuoteFile, "specifies the file containing the quote")
f.Bool(prefix+".use-escape-hatch", DefaultBatchPosterConfig.UseEscapeHatch, "if true, batches will be posted without doing the espresso verification when hotshot is down. If false, wait for hotshot being up")
f.Duration(prefix+".espresso-txns-polling-interval", DefaultBatchPosterConfig.EspressoTxnsPollingInterval, "interval between polling for transactions to be included in the block")
f.Uint64(prefix+".espresso-switch-delay-threshold", DefaultBatchPosterConfig.EspressoSwitchDelayThreshold, "specifies the switch delay threshold used to determine hotshot liveness")
redislock.AddConfigOptions(prefix+".redis-lock", f)
dataposter.DataPosterConfigAddOptions(prefix+".data-poster", f, dataposter.DefaultDataPosterConfig)
genericconf.WalletConfigAddOptions(prefix+".parent-chain-wallet", f, DefaultBatchPosterConfig.ParentChainWallet.Pathname)
Expand Down Expand Up @@ -278,6 +282,8 @@ var DefaultBatchPosterConfig = BatchPosterConfig{
UserDataAttestationFile: "",
QuoteFile: "",
UseEscapeHatch: false,
EspressoTxnsPollingInterval: time.Millisecond * 100,
EspressoSwitchDelayThreshold: 20,
}

var DefaultBatchPosterL1WalletConfig = genericconf.WalletConfig{
Expand Down Expand Up @@ -310,6 +316,8 @@ var TestBatchPosterConfig = BatchPosterConfig{
GasEstimateBaseFeeMultipleBips: arbmath.OneInUBips * 3 / 2,
CheckBatchCorrectness: true,
UseEscapeHatch: false,
EspressoTxnsPollingInterval: time.Millisecond * 100,
EspressoSwitchDelayThreshold: 10,
}

type BatchPosterOpts struct {
Expand Down Expand Up @@ -374,6 +382,8 @@ func NewBatchPoster(ctx context.Context, opts *BatchPosterOpts) (*BatchPoster, e
}

opts.Streamer.UseEscapeHatch = opts.Config().UseEscapeHatch
opts.Streamer.espressoTxnsPollingInterval = opts.Config().EspressoTxnsPollingInterval
opts.Streamer.espressoSwitchDelayThreshold = opts.Config().EspressoSwitchDelayThreshold

b := &BatchPoster{
l1Reader: opts.L1Reader,
Expand Down
55 changes: 24 additions & 31 deletions arbnode/transaction_streamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@ type TransactionStreamer struct {
inboxReader *InboxReader
delayedBridge *DelayedBridge

espressoClient *espressoClient.Client
lightClientReader lightclient.LightClientReaderInterface
// Espresso specific fields. These fields are set from batch poster
espressoClient *espressoClient.Client
lightClientReader lightclient.LightClientReaderInterface
espressoTxnsPollingInterval time.Duration
espressoSwitchDelayThreshold uint64
// Public these fields for testing
HotshotDown bool
UseEscapeHatch bool
Expand All @@ -89,36 +92,26 @@ type TransactionStreamerConfig struct {
MaxBroadcasterQueueSize int `koanf:"max-broadcaster-queue-size"`
MaxReorgResequenceDepth int64 `koanf:"max-reorg-resequence-depth" reload:"hot"`
ExecuteMessageLoopDelay time.Duration `koanf:"execute-message-loop-delay" reload:"hot"`

// Espresso specific fields
EspressoTxnsPollingInterval time.Duration `koanf:"espresso-txns-polling-interval"`
EspressoSwitchDelayThreshold uint64 `koanf:"espresso-switch-delay-threshold"`
}

type TransactionStreamerConfigFetcher func() *TransactionStreamerConfig

var DefaultTransactionStreamerConfig = TransactionStreamerConfig{
MaxBroadcasterQueueSize: 50_000,
MaxReorgResequenceDepth: 1024,
ExecuteMessageLoopDelay: time.Millisecond * 100,
EspressoTxnsPollingInterval: time.Millisecond * 100,
EspressoSwitchDelayThreshold: 20,
MaxBroadcasterQueueSize: 50_000,
MaxReorgResequenceDepth: 1024,
ExecuteMessageLoopDelay: time.Millisecond * 100,
}

var TestTransactionStreamerConfig = TransactionStreamerConfig{
MaxBroadcasterQueueSize: 10_000,
MaxReorgResequenceDepth: 128 * 1024,
ExecuteMessageLoopDelay: time.Millisecond,
EspressoTxnsPollingInterval: time.Millisecond * 100,
EspressoSwitchDelayThreshold: 10,
MaxBroadcasterQueueSize: 10_000,
MaxReorgResequenceDepth: 128 * 1024,
ExecuteMessageLoopDelay: time.Millisecond,
}

func TransactionStreamerConfigAddOptions(prefix string, f *flag.FlagSet) {
f.Int(prefix+".max-broadcaster-queue-size", DefaultTransactionStreamerConfig.MaxBroadcasterQueueSize, "maximum cache of pending broadcaster messages")
f.Int64(prefix+".max-reorg-resequence-depth", DefaultTransactionStreamerConfig.MaxReorgResequenceDepth, "maximum number of messages to attempt to resequence on reorg (0 = never resequence, -1 = always resequence)")
f.Duration(prefix+".execute-message-loop-delay", DefaultTransactionStreamerConfig.ExecuteMessageLoopDelay, "delay when polling calls to execute messages")
f.Duration(prefix+".espresso-txns-polling-interval", DefaultTransactionStreamerConfig.EspressoTxnsPollingInterval, "interval between polling for transactions to be included in the block")
f.Uint64(prefix+".espresso-switch-delay-threshold", DefaultTransactionStreamerConfig.EspressoSwitchDelayThreshold, "specifies the switch delay threshold used to determine hotshot liveness")
}

func NewTransactionStreamer(
Expand Down Expand Up @@ -1615,7 +1608,7 @@ func (s *TransactionStreamer) submitEspressoTransactions(ctx context.Context) ti

pendingTxnsPos, err := s.getEspressoPendingTxnsPos()
if err != nil {
return s.config().EspressoTxnsPollingInterval
return s.espressoTxnsPollingInterval
}

if len(pendingTxnsPos) > 0 {
Expand All @@ -1625,7 +1618,7 @@ func (s *TransactionStreamer) submitEspressoTransactions(ctx context.Context) ti
msg, err := s.GetMessage(pos)
if err != nil {
log.Error("failed to get espresso submitted pos", "err", err)
return s.config().EspressoTxnsPollingInterval
return s.espressoTxnsPollingInterval
}
if msg.Message != nil {
msgs = append(msgs, *msg.Message)
Expand All @@ -1634,7 +1627,7 @@ func (s *TransactionStreamer) submitEspressoTransactions(ctx context.Context) ti
payload, msgCnt := arbos.BuildHotShotPayload(&msgs)
if msgCnt == 0 {
log.Error("failed to build the hotshot transaction: a large message has exceeded the size limit")
return s.config().EspressoTxnsPollingInterval
return s.espressoTxnsPollingInterval
}

log.Info("submitting transaction to espresso using sovereign sequencer")
Expand All @@ -1647,7 +1640,7 @@ func (s *TransactionStreamer) submitEspressoTransactions(ctx context.Context) ti

if err != nil {
log.Error("failed to submit transaction to espresso", "err", err)
return s.config().EspressoTxnsPollingInterval
return s.espressoTxnsPollingInterval
}

s.espressoTxnsStateInsertionMutex.Lock()
Expand All @@ -1658,32 +1651,32 @@ func (s *TransactionStreamer) submitEspressoTransactions(ctx context.Context) ti
err = s.setEspressoSubmittedPos(batch, submittedPos)
if err != nil {
log.Error("failed to set the submitted txn pos", "err", err)
return s.config().EspressoTxnsPollingInterval
return s.espressoTxnsPollingInterval
}
pendingTxnsPos = pendingTxnsPos[msgCnt:]
err = s.setEspressoPendingTxnsPos(batch, pendingTxnsPos)
if err != nil {
log.Error("failed to set the pending txns", "err", err)
return s.config().EspressoTxnsPollingInterval
return s.espressoTxnsPollingInterval
}
err = s.setEspressoSubmittedHash(batch, hash)
if err != nil {
log.Error("failed to set the submitted hash", "err", err)
return s.config().EspressoTxnsPollingInterval
return s.espressoTxnsPollingInterval
}

err = batch.Write()
if err != nil {
log.Error("failed to write to db", "err", err)
return s.config().EspressoTxnsPollingInterval
return s.espressoTxnsPollingInterval
}
}

return s.config().EspressoTxnsPollingInterval
return s.espressoTxnsPollingInterval
}

func (s *TransactionStreamer) toggleEscapeHatch(ctx context.Context) error {
live, err := s.lightClientReader.IsHotShotLive(s.config().EspressoSwitchDelayThreshold)
live, err := s.lightClientReader.IsHotShotLive(s.espressoSwitchDelayThreshold)
if err != nil {
return err
}
Expand Down Expand Up @@ -1726,7 +1719,7 @@ func (s *TransactionStreamer) toggleEscapeHatch(ctx context.Context) error {
}

l1Height := header.Header.GetL1Head()
hotshotLive, err := s.lightClientReader.IsHotShotLiveAtHeight(l1Height, s.config().EspressoSwitchDelayThreshold)
hotshotLive, err := s.lightClientReader.IsHotShotLiveAtHeight(l1Height, s.espressoSwitchDelayThreshold)
if err != nil {
return err
}
Expand Down Expand Up @@ -1778,7 +1771,7 @@ func (s *TransactionStreamer) toggleEscapeHatch(ctx context.Context) error {
}

func (s *TransactionStreamer) espressoSwitch(ctx context.Context, ignored struct{}) time.Duration {
retryRate := s.config().EspressoTxnsPollingInterval * 50
retryRate := s.espressoTxnsPollingInterval * 50
config, err := s.exec.GetArbOSConfigAtHeight(0) // Pass 0 to get the ArbOS config at current block height.
if err != nil {
log.Error("Error Obtaining ArbOS Config ", "err", err)
Expand All @@ -1801,7 +1794,7 @@ func (s *TransactionStreamer) espressoSwitch(ctx context.Context, ignored struct
return s.submitEspressoTransactions(ctx)
}

return s.config().EspressoTxnsPollingInterval
return s.espressoTxnsPollingInterval
} else {
return retryRate
}
Expand Down
65 changes: 9 additions & 56 deletions execution/gethexec/sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"context"
"errors"
"fmt"
lightclient "github.com/EspressoSystems/espresso-sequencer-go/light-client"
"math"
"math/big"
"runtime/debug"
Expand Down Expand Up @@ -80,12 +79,9 @@ type SequencerConfig struct {
expectedSurplusHardThreshold int

// Espresso specific flags
LightClientAddress string `koanf:"light-client-address"`
SwitchDelayThreshold uint64 `koanf:"switch-delay-threshold"`
EspressoFinalityNodeConfig EspressoFinalityNodeConfig `koanf:"espresso-finality-node-config"`
// Espresso Finality Node creates blocks with finalized hotshot transactions
EnableEspressoFinalityNode bool `koanf:"enable-espresso-finality-node"`
EnableEspressoSovereign bool `koanf:"enable-espresso-sovereign"`
}

func (c *SequencerConfig) Validate() error {
Expand Down Expand Up @@ -131,7 +127,6 @@ var DefaultSequencerConfig = SequencerConfig{
EnableProfiling: false,

EnableEspressoFinalityNode: false,
EnableEspressoSovereign: false,
}

func SequencerConfigAddOptions(prefix string, f *flag.FlagSet) {
Expand All @@ -153,7 +148,6 @@ func SequencerConfigAddOptions(prefix string, f *flag.FlagSet) {

// Espresso specific flags
f.Bool(prefix+".enable-espresso-finality-node", DefaultSequencerConfig.EnableEspressoFinalityNode, "enable espresso finality node")
f.Bool(prefix+".enable-espresso-sovereign", DefaultSequencerConfig.EnableEspressoSovereign, "enable sovereign sequencer mode for the Espresso integration")
}

type txQueueItem struct {
Expand Down Expand Up @@ -322,8 +316,6 @@ type Sequencer struct {
expectedSurplusMutex sync.RWMutex
expectedSurplus int64
expectedSurplusUpdated bool

lightClientReader *lightclient.LightClientReader
}

func NewSequencer(execEngine *ExecutionEngine, l1Reader *headerreader.HeaderReader, configFetcher SequencerConfigFetcher) (*Sequencer, error) {
Expand All @@ -339,37 +331,16 @@ func NewSequencer(execEngine *ExecutionEngine, l1Reader *headerreader.HeaderRead
senderWhitelist[common.HexToAddress(address)] = struct{}{}
}

// For the sovereign sequencer to have an escape hatch, we need to be able to read the state of the light client.
// To accomplish this, we introduce a requirement on the l1Reader/ParentChainReader to not be null. This is a soft
// requirement as the sequencer will still run if we don't have this reader, but it will not create espresso messages.
var (
lightClientReader *lightclient.LightClientReader
err error
)

if l1Reader == nil && config.EnableEspressoSovereign {
return nil, fmt.Errorf("Cannot enable espresso sequencing mode in the sovereign sequencer with no l1 reader")
}

if l1Reader != nil {
lightClientReader, err = lightclient.NewLightClientReader(common.HexToAddress(config.LightClientAddress), l1Reader.Client())
if err != nil {
log.Error("Could not construct light client reader for sequencer. Failing.", "err", err)
return nil, err
}
}

s := &Sequencer{
execEngine: execEngine,
txQueue: make(chan txQueueItem, config.QueueSize),
l1Reader: l1Reader,
config: configFetcher,
senderWhitelist: senderWhitelist,
nonceCache: newNonceCache(config.NonceCacheSize),
l1Timestamp: 0,
pauseChan: nil,
onForwarderSet: make(chan struct{}, 1),
lightClientReader: lightClientReader,
execEngine: execEngine,
txQueue: make(chan txQueueItem, config.QueueSize),
l1Reader: l1Reader,
config: configFetcher,
senderWhitelist: senderWhitelist,
nonceCache: newNonceCache(config.NonceCacheSize),
l1Timestamp: 0,
pauseChan: nil,
onForwarderSet: make(chan struct{}, 1),
}
s.nonceFailures = &nonceFailureCache{
containers.NewLruCacheWithOnEvict(config.NonceCacheSize, s.onNonceFailureEvict),
Expand Down Expand Up @@ -944,24 +915,6 @@ func (s *Sequencer) createBlock(ctx context.Context) (returnValue bool) {
shouldSequenceWithEspresso bool
)

arbOSconfig, err := s.execEngine.GetArbOSConfigAtHeight(0) // pass 0 to get the current ArbOS config.
if err != nil {
log.Warn("Error fetching ArbOS chainConfig in sequencer.")
}

// Initialize shouldSequenceWithEspresso to false and if we have a light client reader then give it a value based on hotshot liveness
// This is a side effect of the sequencer having the capability to run without an L1 reader. For the Espresso integration this is a necessary component of the sequencer.
// However, many tests use the case of having a nil l1 reader
if s.lightClientReader != nil && arbOSconfig != nil {
isHotShotLive, err := s.lightClientReader.IsHotShotLiveAtHeight(l1Block, s.config().SwitchDelayThreshold)
if err != nil {
log.Warn("An error occurred while attempting to determine if hotshot is live at l1 block, sequencing transactions without espresso", "l1Block", l1Block, "err", err)
}
shouldSequenceWithEspresso = isHotShotLive && arbOSconfig.ArbitrumChainParams.EnableEspresso

log.Info("After escape-hatch and chain config logic in sequencer", "ShouldSequenceWithEspresso", shouldSequenceWithEspresso, "EnableEspresso", arbOSconfig.ArbitrumChainParams.EnableEspresso, "isHotShotLive", isHotShotLive)
}

if config.EnableProfiling {
block, err = s.execEngine.SequenceTransactionsWithProfiling(header, txes, hooks, shouldSequenceWithEspresso)
} else {
Expand Down
6 changes: 0 additions & 6 deletions system_tests/espresso_sovereign_sequencer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,10 @@ func createL1AndL2Node(
builder.nodeConfig.Sequencer = true
builder.nodeConfig.ParentChainReader.Enable = true // This flag is necessary to enable sequencing transactions with espresso behavior
builder.nodeConfig.Dangerous.NoSequencerCoordinator = true
builder.execConfig.Sequencer.EnableEspressoSovereign = true
builder.execConfig.Sequencer.Enable = true
builder.execConfig.Sequencer.LightClientAddress = lightClientAddress
builder.execConfig.Sequencer.SwitchDelayThreshold = 5
builder.execConfig.Caching.StateScheme = "hash"
builder.execConfig.Caching.Archive = true

// transaction stream config
builder.nodeConfig.TransactionStreamer.EspressoSwitchDelayThreshold = 5

cleanup := builder.Build(t)

mnemonic := "indoor dish desk flag debris potato excuse depart ticket judge file exit"
Expand Down

0 comments on commit 6862859

Please sign in to comment.