Skip to content

Commit

Permalink
update geth pin
Browse files Browse the repository at this point in the history
  • Loading branch information
ganeshvanahalli committed Nov 14, 2024
2 parents bbab516 + feaf306 commit 3c491aa
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 53 deletions.
24 changes: 8 additions & 16 deletions execution/gethexec/blockmetadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import (
"context"
"errors"
"fmt"
"sync"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/lru"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/rpc"
"github.com/offchainlabs/nitro/arbutil"
"github.com/offchainlabs/nitro/util/containers"
"github.com/offchainlabs/nitro/util/stopwaiter"
)

Expand All @@ -21,26 +20,25 @@ type BlockMetadataFetcher interface {
BlockMetadataAtCount(count arbutil.MessageIndex) (common.BlockMetadata, error)
BlockNumberToMessageIndex(blockNum uint64) (arbutil.MessageIndex, error)
MessageIndexToBlockNumber(messageNum arbutil.MessageIndex) uint64
SetReorgEventsReader(reorgEventsReader chan struct{})
SetReorgEventsNotifier(reorgEventsNotifier chan struct{})
}

type BulkBlockMetadataFetcher struct {
stopwaiter.StopWaiter
bc *core.BlockChain
fetcher BlockMetadataFetcher
reorgDetector chan struct{}
blocksLimit int
cacheMutex sync.RWMutex
cache *containers.LruCache[arbutil.MessageIndex, common.BlockMetadata]
blocksLimit uint64
cache *lru.SizeConstrainedCache[arbutil.MessageIndex, common.BlockMetadata]
}

func NewBulkBlockMetadataFetcher(bc *core.BlockChain, fetcher BlockMetadataFetcher, cacheSize, blocksLimit int) *BulkBlockMetadataFetcher {
var cache *containers.LruCache[arbutil.MessageIndex, common.BlockMetadata]
func NewBulkBlockMetadataFetcher(bc *core.BlockChain, fetcher BlockMetadataFetcher, cacheSize, blocksLimit uint64) *BulkBlockMetadataFetcher {
var cache *lru.SizeConstrainedCache[arbutil.MessageIndex, common.BlockMetadata]
var reorgDetector chan struct{}
if cacheSize != 0 {
cache = containers.NewLruCache[arbutil.MessageIndex, common.BlockMetadata](cacheSize)
cache = lru.NewSizeConstrainedCache[arbutil.MessageIndex, common.BlockMetadata](cacheSize)
reorgDetector = make(chan struct{})
fetcher.SetReorgEventsReader(reorgDetector)
fetcher.SetReorgEventsNotifier(reorgDetector)
}
return &BulkBlockMetadataFetcher{
bc: bc,
Expand Down Expand Up @@ -73,19 +71,15 @@ func (b *BulkBlockMetadataFetcher) Fetch(fromBlock, toBlock rpc.BlockNumber) ([]
var data common.BlockMetadata
var found bool
if b.cache != nil {
b.cacheMutex.RLock()
data, found = b.cache.Get(i)
b.cacheMutex.RUnlock()
}
if !found {
data, err = b.fetcher.BlockMetadataAtCount(i + 1)
if err != nil {
return nil, err
}
if data != nil && b.cache != nil {
b.cacheMutex.Lock()
b.cache.Add(i, data)
b.cacheMutex.Unlock()
}
}
if data != nil {
Expand All @@ -99,9 +93,7 @@ func (b *BulkBlockMetadataFetcher) Fetch(fromBlock, toBlock rpc.BlockNumber) ([]
}

func (b *BulkBlockMetadataFetcher) ClearCache(ctx context.Context, ignored struct{}) {
b.cacheMutex.Lock()
b.cache.Clear()
b.cacheMutex.Unlock()
}

func (b *BulkBlockMetadataFetcher) Start(ctx context.Context) {
Expand Down
35 changes: 21 additions & 14 deletions execution/gethexec/executionengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ type ExecutionEngine struct {
resequenceChan chan []*arbostypes.MessageWithMetadata
createBlocksMutex sync.Mutex

newBlockNotifier chan struct{}
reorgEventsReader chan struct{}
latestBlockMutex sync.Mutex
latestBlock *types.Block
newBlockNotifier chan struct{}
reorgEventsNotifier chan struct{}
latestBlockMutex sync.Mutex
latestBlock *types.Block

nextScheduledVersionCheck time.Time // protected by the createBlocksMutex

Expand Down Expand Up @@ -135,10 +135,6 @@ func (s *ExecutionEngine) backlogL1GasCharged() uint64 {
s.cachedL1PriceData.msgToL1PriceData[0].l1GasCharged)
}

func (s *ExecutionEngine) SetReorgEventsReader(reorgEventsReader chan struct{}) {
s.reorgEventsReader = reorgEventsReader
}

func (s *ExecutionEngine) MarkFeedStart(to arbutil.MessageIndex) {
s.cachedL1PriceData.mutex.Lock()
defer s.cachedL1PriceData.mutex.Unlock()
Expand Down Expand Up @@ -187,6 +183,16 @@ func (s *ExecutionEngine) SetRecorder(recorder *BlockRecorder) {
s.recorder = recorder
}

func (s *ExecutionEngine) SetReorgEventsNotifier(reorgEventsNotifier chan struct{}) {
if s.Started() {
panic("trying to set reorg events notifier after start")
}
if s.reorgEventsNotifier != nil {
panic("trying to set reorg events notifier when already set")
}
s.reorgEventsNotifier = reorgEventsNotifier
}

func (s *ExecutionEngine) EnableReorgSequencing() {
if s.Started() {
panic("trying to enable reorg sequencing after start")
Expand Down Expand Up @@ -258,6 +264,13 @@ func (s *ExecutionEngine) Reorg(count arbutil.MessageIndex, newMessages []arbost
return nil, err
}

if s.reorgEventsNotifier != nil {
select {
case s.reorgEventsNotifier <- struct{}{}:
default:
}
}

newMessagesResults := make([]*execution.MessageResult, 0, len(oldMessages))
for i := range newMessages {
var msgForPrefetch *arbostypes.MessageWithMetadata
Expand All @@ -277,12 +290,6 @@ func (s *ExecutionEngine) Reorg(count arbutil.MessageIndex, newMessages []arbost
s.resequenceChan <- oldMessages
resequencing = true
}
if s.reorgEventsReader != nil {
select {
case s.reorgEventsReader <- struct{}{}:
default:
}
}
return newMessagesResults, nil
}

Expand Down
16 changes: 5 additions & 11 deletions execution/gethexec/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ type Config struct {
EnablePrefetchBlock bool `koanf:"enable-prefetch-block"`
SyncMonitor SyncMonitorConfig `koanf:"sync-monitor"`
StylusTarget StylusTargetConfig `koanf:"stylus-target"`
BlockMetadataApiCacheSize int `koanf:"block-metadata-api-cache-size"`
BlockMetadataApiBlocksLimit int `koanf:"block-metadata-api-blocks-limit"`
BlockMetadataApiCacheSize uint64 `koanf:"block-metadata-api-cache-size"`
BlockMetadataApiBlocksLimit uint64 `koanf:"block-metadata-api-blocks-limit"`

forwardingTarget string
}
Expand All @@ -84,12 +84,6 @@ func (c *Config) Validate() error {
if c.forwardingTarget != "" && c.Sequencer.Enable {
return errors.New("ForwardingTarget set and sequencer enabled")
}
if c.BlockMetadataApiCacheSize < 0 {
return errors.New("block-metadata-api-cache-size cannot be negative")
}
if c.BlockMetadataApiBlocksLimit < 0 {
return errors.New("block-metadata-api-blocks-limit cannot be negative")
}
return nil
}

Expand All @@ -107,8 +101,8 @@ func ConfigAddOptions(prefix string, f *flag.FlagSet) {
f.Uint64(prefix+".tx-lookup-limit", ConfigDefault.TxLookupLimit, "retain the ability to lookup transactions by hash for the past N blocks (0 = all blocks)")
f.Bool(prefix+".enable-prefetch-block", ConfigDefault.EnablePrefetchBlock, "enable prefetching of blocks")
StylusTargetConfigAddOptions(prefix+".stylus-target", f)
f.Int(prefix+".block-metadata-api-cache-size", ConfigDefault.BlockMetadataApiCacheSize, "size of lru cache storing the blockMetadata to service arb_getRawBlockMetadata")
f.Int(prefix+".block-metadata-api-blocks-limit", ConfigDefault.BlockMetadataApiBlocksLimit, "maximum number of blocks allowed to be queried for blockMetadata per arb_getRawBlockMetadata query. Enabled by default, set 0 to disable")
f.Uint64(prefix+".block-metadata-api-cache-size", ConfigDefault.BlockMetadataApiCacheSize, "size (in bytes) of lru cache storing the blockMetadata to service arb_getRawBlockMetadata")
f.Uint64(prefix+".block-metadata-api-blocks-limit", ConfigDefault.BlockMetadataApiBlocksLimit, "maximum number of blocks allowed to be queried for blockMetadata per arb_getRawBlockMetadata query. Enabled by default, set 0 to disable the limit")
}

var ConfigDefault = Config{
Expand All @@ -124,7 +118,7 @@ var ConfigDefault = Config{
Forwarder: DefaultNodeForwarderConfig,
EnablePrefetchBlock: true,
StylusTarget: DefaultStylusTargetConfig,
BlockMetadataApiCacheSize: 10000,
BlockMetadataApiCacheSize: 100 * 1024 * 1024,
BlockMetadataApiBlocksLimit: 100,
}

Expand Down
2 changes: 1 addition & 1 deletion go-ethereum
55 changes: 44 additions & 11 deletions system_tests/timeboost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import (
"github.com/stretchr/testify/require"
)

var blockMetadataInputFeedKey = func(pos uint64) []byte {
func blockMetadataInputFeedKey(pos uint64) []byte {
var key []byte
prefix := []byte("t")
key = append(key, prefix...)
Expand All @@ -71,17 +71,22 @@ func TestTimeboostedFieldInReceiptsObject(t *testing.T) {
blockNum := big.NewInt(2)
builder.L2Info.GenerateAccount("User")
user := builder.L2Info.GetDefaultTransactOpts("User", ctx)
var latestL2 uint64
var err error
for i := 0; ; i++ {
builder.L2.TransferBalanceTo(t, "Owner", util.RemapL1Address(user.From), big.NewInt(1e18), builder.L2Info)
latestL2, err := builder.L2.Client.BlockNumber(ctx)
latestL2, err = builder.L2.Client.BlockNumber(ctx)
Require(t, err)
// Clean BlockMetadata from arbDB so that we can modify it at will
Require(t, arbDb.Delete(blockMetadataInputFeedKey(latestL2)))
if latestL2 >= blockNum.Uint64() {
break
}
}

for i := uint64(1); i < latestL2; i++ {
// Clean BlockMetadata from arbDB so that we can modify it at will
Require(t, arbDb.Delete(blockMetadataInputFeedKey(i)))
}

block, err := builder.L2.Client.BlockByNumber(ctx, blockNum)
Require(t, err)
if len(block.Transactions()) != 2 {
Expand All @@ -98,11 +103,11 @@ func TestTimeboostedFieldInReceiptsObject(t *testing.T) {
var receiptResult []timeboostedFromReceipt
err = l2rpc.CallContext(ctx, &receiptResult, "eth_getBlockReceipts", rpc.BlockNumber(blockNum.Int64()))
Require(t, err)
if receiptResult[0].Timeboosted != nil {
t.Fatal("timeboosted field shouldn't exist in the receipt object of first tx")
if receiptResult[0].Timeboosted == nil || receiptResult[1].Timeboosted == nil {
t.Fatal("timeboosted field should exist in the receipt object of both- first and second txs")
}
if receiptResult[1].Timeboosted == nil {
t.Fatal("timeboosted field should exist in the receipt object of second tx")
if *receiptResult[0].Timeboosted != false {
t.Fatal("first tx was not timeboosted, but the field indicates otherwise")
}
if *receiptResult[1].Timeboosted != true {
t.Fatal("second tx was timeboosted, but the field indicates otherwise")
Expand All @@ -112,8 +117,11 @@ func TestTimeboostedFieldInReceiptsObject(t *testing.T) {
var txReceipt timeboostedFromReceipt
err = l2rpc.CallContext(ctx, &txReceipt, "eth_getTransactionReceipt", block.Transactions()[0].Hash())
Require(t, err)
if txReceipt.Timeboosted != nil {
t.Fatal("timeboosted field shouldn't exist in the receipt object of first tx")
if txReceipt.Timeboosted == nil {
t.Fatal("timeboosted field should exist in the receipt object of first tx")
}
if *txReceipt.Timeboosted != false {
t.Fatal("first tx was not timeboosted, but the field indicates otherwise")
}
err = l2rpc.CallContext(ctx, &txReceipt, "eth_getTransactionReceipt", block.Transactions()[1].Hash())
Require(t, err)
Expand All @@ -124,6 +132,31 @@ func TestTimeboostedFieldInReceiptsObject(t *testing.T) {
t.Fatal("second tx was timeboosted, but the field indicates otherwise")
}

// Check that timeboosted field shouldn't exist for any txs of block=1, as this block doesn't have blockMetadata
block, err = builder.L2.Client.BlockByNumber(ctx, common.Big1)
Require(t, err)
if len(block.Transactions()) != 2 {
t.Fatalf("expecting two txs in the first block, but found: %d txs", len(block.Transactions()))
}
var receiptResult2 []timeboostedFromReceipt
err = l2rpc.CallContext(ctx, &receiptResult2, "eth_getBlockReceipts", rpc.BlockNumber(1))
Require(t, err)
if receiptResult2[0].Timeboosted != nil || receiptResult2[1].Timeboosted != nil {
t.Fatal("timeboosted field shouldn't exist in the receipt object of all the txs")
}
var txReceipt2 timeboostedFromReceipt
err = l2rpc.CallContext(ctx, &txReceipt2, "eth_getTransactionReceipt", block.Transactions()[0].Hash())
Require(t, err)
if txReceipt2.Timeboosted != nil {
t.Fatal("timeboosted field shouldn't exist in the receipt object of all the txs")
}
var txReceipt3 timeboostedFromReceipt
err = l2rpc.CallContext(ctx, &txReceipt3, "eth_getTransactionReceipt", block.Transactions()[1].Hash())
Require(t, err)
if txReceipt3.Timeboosted != nil {
t.Fatal("timeboosted field shouldn't exist in the receipt object of all the txs")
}

// Print the receipt object for reference
var receiptResultRaw json.RawMessage
err = l2rpc.CallContext(ctx, &receiptResultRaw, "eth_getBlockReceipts", rpc.BlockNumber(blockNum.Int64()))
Expand Down Expand Up @@ -199,7 +232,7 @@ func TestTimeboostBulkBlockMetadataAPI(t *testing.T) {
}

// Test that LRU caching works
builder.execConfig.BlockMetadataApiCacheSize = 10
builder.execConfig.BlockMetadataApiCacheSize = 1000
builder.execConfig.BlockMetadataApiBlocksLimit = 25
builder.RestartL2Node(t)
l2rpc = builder.L2.Stack.Attach()
Expand Down

0 comments on commit 3c491aa

Please sign in to comment.