Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into debug/p2p_bootnode
Browse files Browse the repository at this point in the history
  • Loading branch information
krish-nr committed Jan 11, 2024
2 parents b9c67d0 + 2ebe96c commit ca13956
Show file tree
Hide file tree
Showing 18 changed files with 400 additions and 141 deletions.
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
# Changelog

## v0.2.2

This is a minor release for opBNB Mainnet and Testnet.
It primarily optimizes op-geth and introduces an option to re-announce remote transactions.
Upgrading is optional.

### User Facing Changes

- The startup node will default to using the bootnodes of the opBNB mainnet. If the `--networkid=` is configured as testnet, the testnet bootnodes will be used. If `--bootnodes=` is configured, the specified bootnodes will be used. The configured `--bootnodes=` take precedence over other options.[#32](https://github.com/bnb-chain/op-geth/pull/32)
- Enable re-announce remote transactions by using the flag `--txpool.reannounceremotes=true`.[#33](https://github.com/bnb-chain/op-geth/pull/33)

### Partial Changelog

- [#16](https://github.com/bnb-chain/op-geth/pull/16): fix: wrong event log value
- [#31](https://github.com/bnb-chain/op-geth/pull/31): ci: fix blst error and unknown architecture
- [#32](https://github.com/bnb-chain/op-geth/pull/32): feature: add opBNB bootnodes
- [#33](https://github.com/bnb-chain/op-geth/pull/33): feat: add option to reannounce remote transactions
- [#34](https://github.com/bnb-chain/op-geth/pull/34): fix: clear underpriced buffer

### Docker Images

- ghcr.io/bnb-chain/op-geth:v0.2.2

### Full Changelog

https://github.com/bnb-chain/op-geth/compare/v0.2.1...v0.2.2

## v0.2.1

This is the Fermat Hardfork release for opBNB Mainnet.
Expand Down
8 changes: 6 additions & 2 deletions common/gopool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gopool
import (
"time"

"github.com/ethereum/go-ethereum/log"
"github.com/panjf2000/ants/v2"
)

Expand Down Expand Up @@ -30,8 +31,11 @@ func init() {
}

// Submit submits a task to pool.
func Submit(task func()) error {
return defaultPool.Submit(task)
func Submit(task func()) {
err := defaultPool.Submit(task)
if err != nil {
log.Error("pool submit task fail", "err", err, "task", task)
}
}

// Running returns the number of the currently running goroutines.
Expand Down
17 changes: 16 additions & 1 deletion core/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package core

import (
"errors"
"fmt"

"github.com/ethereum/go-ethereum/common/gopool"
Expand Down Expand Up @@ -106,12 +107,26 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error {
validateRes <- tmpFunc()
})
}
errs := make([]error, 0, len(validateFuns))
for i := 0; i < len(validateFuns); i++ {
err := <-validateRes
errs = append(errs, err)
}
var ancestorErr error
for _, err := range errs {
if err != nil {
return err
if !errors.Is(err, consensus.ErrUnknownAncestor) && !errors.Is(err, consensus.ErrPrunedAncestor) {
//Other errors are returned first.
return err
} else {
ancestorErr = err
}
}
}
//If there are no other errors, but an ancestorErr, return it.
if ancestorErr != nil {
return ancestorErr
}

return nil
}
Expand Down
34 changes: 20 additions & 14 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ type CacheConfig struct {

SnapshotNoBuild bool // Whether the background generation is allowed
SnapshotWait bool // Wait for snapshot construction on startup. TODO(karalabe): This is a dirty hack for testing, nuke it

TrieCommitInterval uint64 // Define a block height interval, commit trie every TrieCommitInterval block height.
}

// defaultCacheConfig are the default caching values if none are specified by the
Expand Down Expand Up @@ -227,7 +229,6 @@ type BlockChain struct {
quit chan struct{} // shutdown signal, closed in Stop.
running int32 // 0 if chain is running, 1 when stopped
procInterrupt int32 // interrupt signaler for block processing
commitLock sync.Mutex // CommitLock is used to protect above field from being modified concurrently

engine consensus.Engine
validator Validator // Block and state validator interface
Expand Down Expand Up @@ -1395,8 +1396,6 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.

postCommitFuncs := []func() error{
func() error {
bc.commitLock.Lock()
defer bc.commitLock.Unlock()

root := block.Root()
// If we're running an archive node, always flush
Expand All @@ -1418,13 +1417,16 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
limit = common.StorageSize(bc.cacheConfig.TrieDirtyLimit) * 1024 * 1024
)
if nodes > limit || imgs > 4*1024*1024 {
bc.triedb.Cap(limit - ethdb.IdealBatchSize)
err := bc.triedb.Cap(limit - ethdb.IdealBatchSize)
if err != nil {
return err
}
}
// Find the next state trie we need to commit
chosen := current - bc.cacheConfig.TriesInMemory
flushInterval := time.Duration(atomic.LoadInt64(&bc.flushInterval))
// If we exceeded time allowance, flush an entire trie to disk
if bc.gcproc > flushInterval {
if bc.gcproc > flushInterval || (bc.cacheConfig.TrieCommitInterval != 0 && chosen%bc.cacheConfig.TrieCommitInterval == 0) {
// If the header is missing (canonical chain behind), we're reorging a low
// diff sidechain. Suspend committing until this operation is completed.
header := bc.GetHeaderByNumber(chosen)
Expand All @@ -1437,7 +1439,10 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
log.Info("State in memory for too long, committing", "time", bc.gcproc, "allowance", flushInterval, "optimum", float64(chosen-bc.lastWrite)/TriesInMemory)
}
// Flush an entire trie and restart the counters
bc.triedb.Commit(header.Root, true)
err := bc.triedb.Commit(header.Root, true)
if err != nil {
return err
}
bc.lastWrite = chosen
bc.gcproc = 0
}
Expand Down Expand Up @@ -1869,14 +1874,6 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals, setHead bool)
vtime := time.Since(vstart)
proctime := time.Since(start) // processing + validation

// pre-cache the block and receipts, so that it can be retrieved quickly by rcp
bc.CacheBlock(block.Hash(), block)
err = types.Receipts(receipts).DeriveFields(bc.chainConfig, block.Hash(), block.NumberU64(), block.Time(), block.BaseFee(), block.Transactions())
if err != nil {
log.Warn("Failed to derive receipt fields", "block", block.Hash(), "err", err)
}
bc.CacheReceipts(block.Hash(), receipts)

// Update the metrics touched during block processing and validation
accountReadTimer.Update(statedb.AccountReads) // Account reads are complete(in processing)
storageReadTimer.Update(statedb.StorageReads) // Storage reads are complete(in processing)
Expand Down Expand Up @@ -1908,6 +1905,15 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals, setHead bool)
if err != nil {
return it.index, err
}

// pre-cache the block and receipts, so that it can be retrieved quickly by rcp
bc.CacheBlock(block.Hash(), block)
err = types.Receipts(receipts).DeriveFields(bc.chainConfig, block.Hash(), block.NumberU64(), block.Time(), block.BaseFee(), block.Transactions())
if err != nil {
log.Warn("Failed to derive receipt fields", "block", block.Hash(), "err", err)
}
bc.CacheReceipts(block.Hash(), receipts)

// Update the metrics touched during block commit
accountCommitTimer.Update(statedb.AccountCommits) // Account commits are complete, we can mark them
storageCommitTimer.Update(statedb.StorageCommits) // Storage commits are complete, we can mark them
Expand Down
12 changes: 0 additions & 12 deletions core/state/state_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/trie"
Expand Down Expand Up @@ -179,31 +178,20 @@ func (s *stateObject) getOriginStorage(key common.Hash) (common.Hash, bool) {
}
// if L1 cache miss, try to get it from shared pool
if s.sharedOriginStorage != nil {
log.Info("debug: sharedOriginStorage not nil", "sharedOriginStorage enabled?", s.db.writeOnSharedStorage)
val, ok := s.sharedOriginStorage.Load(key)
if !ok {
log.Info("debug: get OriginStorage", "key", key, "value", val, "db address", fmt.Sprintf("%p", s))
return common.Hash{}, false
}
s.originStorage[key] = val.(common.Hash)
return val.(common.Hash), true
} else if s.db.writeOnSharedStorage {
log.Info("debug: sharedOriginStorage is nil", "sharedOriginStorage enabled?", s.db.writeOnSharedStorage)
}
return common.Hash{}, false
}

func (s *stateObject) setOriginStorage(key common.Hash, value common.Hash) {
if s.db.writeOnSharedStorage && s.sharedOriginStorage != nil {
log.Info("debug: set OriginStorage", "key", key, "value", value)
s.sharedOriginStorage.Store(key, value)
}
if s.db.writeOnSharedStorage && s.sharedOriginStorage == nil {
log.Info("debug: OriginStorage enabled?", "enabled", s.db.writeOnSharedStorage, "sharedOriginStorage is null", "true")
}
if !s.db.writeOnSharedStorage && s.sharedOriginStorage != nil {
log.Info("debug: OriginStorage enabled?", "enabled", s.db.writeOnSharedStorage, "sharedOriginStorage is null?", "not null")
}
s.originStorage[key] = value
}

Expand Down
1 change: 1 addition & 0 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ func New(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error)

// NewWithSharedPool creates a new state with sharedStorge on layer 1.5
func NewWithSharedPool(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error) {
log.Info("debug: NewWithSharedPool called")
statedb, err := New(root, db, snaps)
if err != nil {
return nil, err
Expand Down
7 changes: 6 additions & 1 deletion core/state_prefetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
)

Expand Down Expand Up @@ -77,7 +78,11 @@ func (p *statePrefetcher) Prefetch(block *types.Block, statedb *state.StateDB, c
return // Also invalid block, bail out
}
newStatedb.SetTxContext(tx.Hash(), i)
precacheTransaction(msg, p.config, gaspool, newStatedb, header, evm)
preCacheErr := precacheTransaction(msg, p.config, gaspool, newStatedb, header, evm)
if preCacheErr != nil {
log.Warn("precacheTransaction fail", "err", preCacheErr)
return
}

case <-interruptCh:
// If block precaching was interrupted, abort
Expand Down
68 changes: 68 additions & 0 deletions core/txpool/invalid.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package txpool

import (
"github.com/ethereum/go-ethereum/metrics"
)

const (
AlreadyKnown = "AlreadyKnown"
TypeNotSupportDeposit = "TypeNotSupportDeposit"
TypeNotSupport1559 = "TypeNotSupport1559"
TypeNotSupport2718 = "TypeNotSupport2718"
MissingTransaction = "MissingTransaction"
OversizedData = "OversizedData"
MaxInitCodeSizeExceeded = "MaxInitCodeSizeExceeded"
NegativeValue = "NegativeValue"
GasLimit = "GasLimit"
FeeCapVeryHigh = "FeeCapVeryHigh"
TipVeryHigh = "TipVeryHigh"
TipAboveFeeCap = "TipAboveFeeCap"
InvalidSender = "InvalidSender"
Underpriced = "Underpriced"
NonceTooLow = "NonceTooLow"
InsufficientFunds = "InsufficientFunds"
Overdraft = "Overdraft"
IntrinsicGas = "IntrinsicGas"
Throttle = "Throttle"
Overflow = "Overflow"
FutureReplacePending = "FutureReplacePending"
ReplaceUnderpriced = "ReplaceUnderpriced"
QueuedDiscard = "QueueDiscard"
GasUnitOverflow = "GasUnitOverflow"
)

func meter(err string) metrics.Meter {
return metrics.GetOrRegisterMeter("txpool/invalid/"+err, nil)
}

func init() {
// init the metrics
for _, err := range []string{
AlreadyKnown,
TypeNotSupportDeposit,
TypeNotSupport1559,
TypeNotSupport2718,
MissingTransaction,
OversizedData,
MaxInitCodeSizeExceeded,
NegativeValue,
GasLimit,
FeeCapVeryHigh,
TipVeryHigh,
TipAboveFeeCap,
InvalidSender,
Underpriced,
NonceTooLow,
InsufficientFunds,
Overdraft,
IntrinsicGas,
Throttle,
Overflow,
FutureReplacePending,
ReplaceUnderpriced,
QueuedDiscard,
GasUnitOverflow,
} {
meter(err).Mark(0)
}
}
Loading

0 comments on commit ca13956

Please sign in to comment.