Skip to content

Commit

Permalink
merge develop to resolve conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
andyzhang2023 committed Jan 5, 2024
2 parents f8b8ce2 + 95d5458 commit f71fadb
Show file tree
Hide file tree
Showing 14 changed files with 252 additions and 39 deletions.
1 change: 1 addition & 0 deletions .github/workflows/docker-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ jobs:
context: .
file: ./Dockerfile
push: true
provenance: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
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
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ COPY go.sum /go-ethereum/
RUN cd /go-ethereum && go mod download

ADD . /go-ethereum
ENV CGO_CFLAGS="-O -D__BLST_PORTABLE__"
ENV CGO_CFLAGS_ALLOW="-O -D__BLST_PORTABLE__"
RUN cd /go-ethereum && go run build/ci.go install -static ./cmd/geth

# Pull Geth into a second stage deploy alpine container
Expand Down
1 change: 1 addition & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ var (
utils.TxPoolGlobalQueueFlag,
utils.TxPoolLifetimeFlag,
utils.TxPoolReannounceTimeFlag,
utils.TxPoolReannounceRemotesFlag,
utils.SyncModeFlag,
utils.SyncTargetFlag,
utils.ExitWhenSyncedFlag,
Expand Down
17 changes: 16 additions & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,12 @@ var (
Value: ethconfig.Defaults.TxPool.ReannounceTime,
Category: flags.TxPoolCategory,
}
TxPoolReannounceRemotesFlag = &cli.BoolFlag{
Name: "txpool.reannounceremotes",
Usage: "Wether reannnounce remote transactions or not(default = false)",
Value: ethconfig.Defaults.TxPool.ReannounceRemotes,
Category: flags.TxPoolCategory,
}

// Performance tuning settings
CacheFlag = &cli.IntFlag{
Expand Down Expand Up @@ -1135,7 +1141,13 @@ func setNodeUserIdent(ctx *cli.Context, cfg *node.Config) {
// setBootstrapNodes creates a list of bootstrap nodes from the command line
// flags, reverting to pre-configured ones if none have been specified.
func setBootstrapNodes(ctx *cli.Context, cfg *p2p.Config) {
urls := params.MainnetBootnodes
urls := params.OpBNBMainnetBootnodes
if ctx.IsSet(NetworkIdFlag.Name) {
networkId := ctx.Uint64(NetworkIdFlag.Name)
if networkId == params.OpBNBTestnet {
urls = params.OpBNBTestnetBootnodes
}
}
switch {
case ctx.IsSet(BootnodesFlag.Name):
urls = SplitAndTrim(ctx.String(BootnodesFlag.Name))
Expand Down Expand Up @@ -1663,6 +1675,9 @@ func setTxPool(ctx *cli.Context, cfg *txpool.Config) {
if ctx.IsSet(TxPoolReannounceTimeFlag.Name) {
cfg.ReannounceTime = ctx.Duration(TxPoolReannounceTimeFlag.Name)
}
if ctx.IsSet(TxPoolReannounceRemotesFlag.Name) {
cfg.ReannounceRemotes = ctx.Bool(TxPoolReannounceRemotesFlag.Name)
}
}

func setEthash(ctx *cli.Context, cfg *ethconfig.Config) {
Expand Down
2 changes: 1 addition & 1 deletion core/state/pruner/pruner.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ func (p *Pruner) Prune(root common.Hash) error {
}
} else {
if len(layers) > 0 {
log.Info("Selecting bottom-most difflayer as the pruning target", "root", root, "height", p.chainHeader.Number.Uint64()-127)
log.Info("Selecting bottom-most difflayer as the pruning target", "root", root, "height", p.chainHeader.Number.Uint64()-(p.triesInMemory-1))
} else {
log.Info("Selecting user-specified state as the pruning target", "root", root)
}
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)
}
}
34 changes: 31 additions & 3 deletions core/txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,9 @@ type Config struct {
AccountQueue uint64 // Maximum number of non-executable transaction slots permitted per account
GlobalQueue uint64 // Maximum number of non-executable transaction slots for all accounts

Lifetime time.Duration // Maximum amount of time non-executable transaction are queued
ReannounceTime time.Duration // Duration for announcing local pending transactions again
Lifetime time.Duration // Maximum amount of time non-executable transaction are queued
ReannounceTime time.Duration // Duration for announcing local pending transactions again
ReannounceRemotes bool // Wether reannounce remote transactions or not
}

// DefaultConfig contains the default configurations for the transaction
Expand Down Expand Up @@ -433,7 +434,7 @@ func (pool *TxPool) loop() {
reannoTxs := func() []*types.Transaction {
txs := make([]*types.Transaction, 0)
for addr, list := range pool.pending {
if !pool.locals.contains(addr) {
if !pool.config.ReannounceRemotes && !pool.locals.contains(addr) {
continue
}

Expand Down Expand Up @@ -652,55 +653,68 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
// This is for spam protection, not consensus,
// as the external engine-API user authenticates deposits.
if tx.Type() == types.DepositTxType {
meter(TypeNotSupportDeposit).Mark(1)
return core.ErrTxTypeNotSupported
}
// Accept only legacy transactions until EIP-2718/2930 activates.
if !pool.eip2718 && tx.Type() != types.LegacyTxType {
meter(TypeNotSupport2718).Mark(1)
return core.ErrTxTypeNotSupported
}
// Reject dynamic fee transactions until EIP-1559 activates.
if !pool.eip1559 && tx.Type() == types.DynamicFeeTxType {
meter(TypeNotSupport1559).Mark(1)
return core.ErrTxTypeNotSupported
}
// Reject transactions over defined size to prevent DOS attacks
if tx.Size() > txMaxSize {
meter(OversizedData).Mark(1)
return ErrOversizedData
}
// Check whether the init code size has been exceeded.
if pool.shanghai && tx.To() == nil && len(tx.Data()) > params.MaxInitCodeSize {
meter(MaxInitCodeSizeExceeded).Mark(1)
return fmt.Errorf("%w: code size %v limit %v", core.ErrMaxInitCodeSizeExceeded, len(tx.Data()), params.MaxInitCodeSize)
}
// Transactions can't be negative. This may never happen using RLP decoded
// transactions but may occur if you create a transaction using the RPC.
if tx.Value().Sign() < 0 {
meter(NegativeValue).Mark(1)
return ErrNegativeValue
}
// Ensure the transaction doesn't exceed the current block limit gas.
if pool.currentMaxGas < tx.Gas() {
meter(GasLimit).Mark(1)
return ErrGasLimit
}
// Sanity check for extremely large numbers
if tx.GasFeeCap().BitLen() > 256 {
meter(FeeCapVeryHigh).Mark(1)
return core.ErrFeeCapVeryHigh
}
if tx.GasTipCap().BitLen() > 256 {
meter(TipVeryHigh).Mark(1)
return core.ErrTipVeryHigh
}
// Ensure gasFeeCap is greater than or equal to gasTipCap.
if tx.GasFeeCapIntCmp(tx.GasTipCap()) < 0 {
meter(TipAboveFeeCap).Mark(1)
return core.ErrTipAboveFeeCap
}
// Make sure the transaction is signed properly.
from, err := types.Sender(pool.signer, tx)
if err != nil {
meter(InvalidSender).Mark(1)
return ErrInvalidSender
}
// Drop non-local transactions under our own minimal accepted gas price or tip
if !local && tx.GasTipCapIntCmp(pool.gasPrice) < 0 {
meter(Underpriced).Mark(1)
return ErrUnderpriced
}
// Ensure the transaction adheres to nonce ordering
if pool.currentState.GetNonce(from) > tx.Nonce() {
meter(NonceTooLow).Mark(1)
return core.ErrNonceTooLow
}
// Transactor should have enough funds to cover the costs
Expand All @@ -711,6 +725,7 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
}
balance := pool.currentState.GetBalance(from)
if balance.Cmp(cost) < 0 {
meter(InsufficientFunds).Mark(1)
return core.ErrInsufficientFunds
}

Expand All @@ -728,16 +743,19 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
}
if balance.Cmp(sum) < 0 {
log.Trace("Replacing transactions would overdraft", "sender", from, "balance", pool.currentState.GetBalance(from), "required", sum)
meter(Overdraft).Mark(1)
return ErrOverdraft
}
}

// Ensure the transaction has more gas than the basic tx fee.
intrGas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.To() == nil, true, pool.istanbul, pool.shanghai)
if err != nil {
meter(GasUnitOverflow).Mark(1)
return err
}
if tx.Gas() < intrGas {
meter(IntrinsicGas).Mark(1)
return core.ErrIntrinsicGas
}
return nil
Expand All @@ -756,6 +774,7 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err e
if pool.all.Get(hash) != nil {
log.Trace("Discarding already known transaction", "hash", hash)
knownTxMeter.Mark(1)
meter(AlreadyKnown).Mark(1)
return false, ErrAlreadyKnown
}
// Make the local flag. If it's from local source or it's from the network but
Expand All @@ -778,6 +797,7 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err e
if !isLocal && pool.priced.Underpriced(tx) {
log.Trace("Discarding underpriced transaction", "hash", hash, "gasTipCap", tx.GasTipCap(), "gasFeeCap", tx.GasFeeCap())
underpricedTxMeter.Mark(1)
meter(Underpriced).Mark(1)
return false, ErrUnderpriced
}

Expand All @@ -787,6 +807,7 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err e
// replacements to 25% of the slots
if pool.changesSinceReorg > int(pool.config.GlobalSlots/4) {
throttleTxMeter.Mark(1)
meter(Throttle).Mark(1)
return false, ErrTxPoolOverflow
}

Expand All @@ -799,6 +820,7 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err e
if !isLocal && !success {
log.Trace("Discarding overflown transaction", "hash", hash)
overflowedTxMeter.Mark(1)
meter(Overflow).Mark(1)
return false, ErrTxPoolOverflow
}

Expand All @@ -818,6 +840,7 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err e
pool.priced.Put(dropTx, false)
}
log.Trace("Discarding future transaction replacing pending tx", "hash", hash)
meter(FutureReplacePending).Mark(1)
return false, ErrFutureReplacePending
}
}
Expand All @@ -837,6 +860,7 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err e
inserted, old := list.Add(tx, pool.config.PriceBump)
if !inserted {
pendingDiscardMeter.Mark(1)
meter(ReplaceUnderpriced).Mark(1)
return false, ErrReplaceUnderpriced
}
// New transaction is better, replace old one
Expand Down Expand Up @@ -902,6 +926,7 @@ func (pool *TxPool) enqueueTx(hash common.Hash, tx *types.Transaction, local boo
if !inserted {
// An older transaction was better, discard this
queuedDiscardMeter.Mark(1)
meter(QueuedDiscard).Mark(1)
return false, ErrReplaceUnderpriced
}
// Discard any previous transaction and mark this
Expand All @@ -916,6 +941,7 @@ func (pool *TxPool) enqueueTx(hash common.Hash, tx *types.Transaction, local boo
// If the transaction isn't in lookup set but it's expected to be there,
// show the error log.
if pool.all.Get(hash) == nil && !addAll {
meter(MissingTransaction).Mark(1)
log.Error("Missing transaction in lookup set, please report the issue", "hash", hash)
}
if addAll {
Expand Down Expand Up @@ -1034,6 +1060,7 @@ func (pool *TxPool) addTxs(txs []*types.Transaction, local, sync bool) []error {
if pool.all.Get(tx.Hash()) != nil {
errs[i] = ErrAlreadyKnown
knownTxMeter.Mark(1)
meter(AlreadyKnown).Mark(1)
continue
}
// Exclude transactions with invalid signatures as soon as
Expand All @@ -1043,6 +1070,7 @@ func (pool *TxPool) addTxs(txs []*types.Transaction, local, sync bool) []error {
if err != nil {
errs[i] = ErrInvalidSender
invalidTxMeter.Mark(1)
meter(InvalidSender).Mark(1)
continue
}
// Accumulate all unknown transactions for deeper processing
Expand Down
7 changes: 7 additions & 0 deletions core/types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,13 @@ func (tx *Transaction) EffectiveGasTipIntCmp(other *big.Int, baseFee *big.Int) i
return tx.EffectiveGasTipValue(baseFee).Cmp(other)
}

// SetTime sets the decoding time of a transaction. This is used by tests to set
// arbitrary times and by persistent transaction pools when loading old txs from
// disk.
func (tx *Transaction) SetTime(t time.Time) {
tx.time = t
}

// Hash returns the transaction hash.
func (tx *Transaction) Hash() common.Hash {
if hash := tx.hash.Load(); hash != nil {
Expand Down
Loading

0 comments on commit f71fadb

Please sign in to comment.