mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 07:06:42 +00:00
fix testcases
This commit is contained in:
parent
cc2c27dbd3
commit
4e3bcbc90d
6 changed files with 616 additions and 671 deletions
|
|
@ -37,7 +37,6 @@ import (
|
|||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/metrics"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
"github.com/holiman/uint256"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -1444,8 +1443,7 @@ func (pool *LegacyPool) promoteExecutables(accounts []common.Address) []*types.T
|
|||
}
|
||||
log.Trace("Removed old queued transactions", "count", len(forwards))
|
||||
// Drop all transactions that are too costly (low balance or out of gas)
|
||||
balUint256, _ := uint256.FromBig(pool.currentState.GetBalance(addr))
|
||||
drops, _ := list.Filter(balUint256, gasLimit)
|
||||
drops, _ := list.Filter(pool.currentState.GetBalance(addr), gasLimit)
|
||||
for _, tx := range drops {
|
||||
hash := tx.Hash()
|
||||
pool.all.Remove(hash)
|
||||
|
|
@ -1646,8 +1644,7 @@ func (pool *LegacyPool) demoteUnexecutables() {
|
|||
log.Trace("Removed old pending transaction", "hash", hash)
|
||||
}
|
||||
// Drop all transactions that are too costly (low balance or out of gas), and queue any invalids back for later
|
||||
balUint256, _ := uint256.FromBig(pool.currentState.GetBalance(addr))
|
||||
drops, invalids := list.Filter(balUint256, gasLimit)
|
||||
drops, invalids := list.Filter(pool.currentState.GetBalance(addr), gasLimit)
|
||||
for _, tx := range drops {
|
||||
hash := tx.Hash()
|
||||
log.Trace("Removed unpayable pending transaction", "hash", hash)
|
||||
|
|
|
|||
|
|
@ -25,10 +25,7 @@ import (
|
|||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/holiman/uint256"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
cmath "github.com/ethereum/go-ethereum/common/math"
|
||||
"github.com/ethereum/go-ethereum/core/state"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
|
|
@ -155,46 +152,19 @@ func (m *sortedMap) Filter(filter func(*types.Transaction) bool) types.Transacti
|
|||
removed := m.filter(filter)
|
||||
// If transactions were removed, the heap and cache are ruined
|
||||
if len(removed) > 0 {
|
||||
m.reheap(false)
|
||||
m.reheap()
|
||||
}
|
||||
|
||||
return removed
|
||||
}
|
||||
|
||||
func (m *sortedMap) reheap(withRlock bool) {
|
||||
index := make(nonceHeap, 0, len(m.items))
|
||||
|
||||
if withRlock {
|
||||
m.m.RLock()
|
||||
log.Debug("Acquired lock over txpool map while performing reheap")
|
||||
}
|
||||
|
||||
func (m *sortedMap) reheap() {
|
||||
*m.index = make([]uint64, 0, len(m.items))
|
||||
for nonce := range m.items {
|
||||
index = append(index, nonce)
|
||||
*m.index = append(*m.index, nonce)
|
||||
}
|
||||
|
||||
if withRlock {
|
||||
m.m.RUnlock()
|
||||
}
|
||||
|
||||
heap.Init(&index)
|
||||
|
||||
if withRlock {
|
||||
m.m.Lock()
|
||||
}
|
||||
|
||||
m.index = &index
|
||||
|
||||
if withRlock {
|
||||
m.m.Unlock()
|
||||
}
|
||||
|
||||
m.cacheMu.Lock()
|
||||
heap.Init(m.index)
|
||||
m.cache = nil
|
||||
m.isEmpty = true
|
||||
m.cacheMu.Unlock()
|
||||
|
||||
resetCacheGauge.Inc(1)
|
||||
}
|
||||
|
||||
// filter is identical to Filter, but **does not** regenerate the heap. This method
|
||||
|
|
@ -431,9 +401,9 @@ type list struct {
|
|||
strict bool // Whether nonces are strictly continuous or not
|
||||
txs *sortedMap // Heap indexed sorted hash map of the transactions
|
||||
|
||||
costcap *uint256.Int // Price of the highest costing transaction (reset only if exceeds balance)
|
||||
gascap uint64 // Gas limit of the highest spending transaction (reset only if exceeds block limit)
|
||||
totalcost *big.Int // Total cost of all transactions in the list
|
||||
costcap *big.Int // Price of the highest costing transaction (reset only if exceeds balance)
|
||||
gascap uint64 // Gas limit of the highest spending transaction (reset only if exceeds block limit)
|
||||
totalcost *big.Int // Total cost of all transactions in the list
|
||||
}
|
||||
|
||||
// newList create a new transaction list for maintaining nonce-indexable fast,
|
||||
|
|
@ -442,6 +412,7 @@ func newList(strict bool) *list {
|
|||
return &list{
|
||||
strict: strict,
|
||||
txs: newSortedMap(),
|
||||
costcap: new(big.Int),
|
||||
totalcost: new(big.Int),
|
||||
}
|
||||
}
|
||||
|
|
@ -487,10 +458,8 @@ func (l *list) Add(tx *types.Transaction, priceBump uint64) (bool, *types.Transa
|
|||
l.totalcost.Add(l.totalcost, tx.Cost())
|
||||
// Otherwise overwrite the old transaction with the current one
|
||||
l.txs.Put(tx)
|
||||
cost := tx.Cost()
|
||||
costUint256, _ := uint256.FromBig(cost)
|
||||
if cost = tx.Cost(); l.costcap.Cmp(costUint256) < 0 {
|
||||
l.costcap = costUint256
|
||||
if cost := tx.Cost(); l.costcap.Cmp(cost) < 0 {
|
||||
l.costcap = cost
|
||||
}
|
||||
if gas := tx.Gas(); l.gascap < gas {
|
||||
l.gascap = gas
|
||||
|
|
@ -517,26 +486,22 @@ func (l *list) Forward(threshold uint64) types.Transactions {
|
|||
// a point in calculating all the costs or if the balance covers all. If the threshold
|
||||
// is lower than the costgas cap, the caps will be reset to a new high after removing
|
||||
// the newly invalidated transactions.
|
||||
func (l *list) Filter(costLimit *uint256.Int, gasLimit uint64) (types.Transactions, types.Transactions) {
|
||||
func (l *list) Filter(costLimit *big.Int, gasLimit uint64) (types.Transactions, types.Transactions) {
|
||||
// If all transactions are below the threshold, short circuit
|
||||
if cmath.U256LTE(l.costcap, costLimit) && l.gascap <= gasLimit {
|
||||
if l.costcap.Cmp(costLimit) <= 0 && l.gascap <= gasLimit {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
l.costcap = costLimit.Clone() // Lower the caps to the thresholds
|
||||
l.costcap = new(big.Int).Set(costLimit) // Lower the caps to the thresholds
|
||||
l.gascap = gasLimit
|
||||
|
||||
// Filter out all the transactions above the account's funds
|
||||
cost := uint256.NewInt(0)
|
||||
removed := l.txs.Filter(func(tx *types.Transaction) bool {
|
||||
cost.SetFromBig(tx.Cost())
|
||||
return tx.Gas() > gasLimit || cost.Gt(costLimit)
|
||||
return tx.Gas() > gasLimit || tx.Cost().Cmp(costLimit) > 0
|
||||
})
|
||||
|
||||
if len(removed) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var invalids types.Transactions
|
||||
// If the list was strict, filter anything above the lowest nonce
|
||||
if l.strict {
|
||||
|
|
@ -546,17 +511,12 @@ func (l *list) Filter(costLimit *uint256.Int, gasLimit uint64) (types.Transactio
|
|||
lowest = nonce
|
||||
}
|
||||
}
|
||||
|
||||
l.txs.m.Lock()
|
||||
invalids = l.txs.filter(func(tx *types.Transaction) bool { return tx.Nonce() > lowest })
|
||||
l.txs.m.Unlock()
|
||||
}
|
||||
// Reset total cost
|
||||
l.subTotalCost(removed)
|
||||
l.subTotalCost(invalids)
|
||||
|
||||
l.txs.reheap(true)
|
||||
|
||||
l.txs.reheap()
|
||||
return removed, invalids
|
||||
}
|
||||
|
||||
|
|
@ -581,7 +541,7 @@ func (l *list) FilterTxConditional(state *state.StateDB) types.Transactions {
|
|||
return nil
|
||||
}
|
||||
|
||||
l.txs.reheap(true)
|
||||
l.txs.reheap()
|
||||
|
||||
return removed
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ import (
|
|||
"math/rand"
|
||||
"testing"
|
||||
|
||||
"github.com/holiman/uint256"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
|
|
@ -70,15 +69,12 @@ func BenchmarkListAdd(b *testing.B) {
|
|||
}
|
||||
// Insert the transactions in a random order
|
||||
priceLimit := big.NewInt(int64(DefaultConfig.PriceLimit))
|
||||
|
||||
b.ResetTimer()
|
||||
b.ReportAllocs()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
list := newList(true)
|
||||
for _, v := range rand.Perm(len(txs)) {
|
||||
list.Add(txs[v], DefaultConfig.PriceBump)
|
||||
list.Filter(uint256.NewInt(priceLimit.Uint64()), DefaultConfig.PriceBump)
|
||||
list.Filter(priceLimit, DefaultConfig.PriceBump)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -915,17 +915,14 @@ func (s *BlockChainAPI) GetHeaderByNumber(ctx context.Context, number rpc.BlockN
|
|||
header, err := s.b.HeaderByNumber(ctx, number)
|
||||
if header != nil && err == nil {
|
||||
response := s.rpcMarshalHeader(ctx, header)
|
||||
|
||||
if number == rpc.PendingBlockNumber {
|
||||
// Pending header need to nil out a few fields
|
||||
for _, field := range []string{"hash", "nonce", "miner"} {
|
||||
response[field] = nil
|
||||
}
|
||||
}
|
||||
|
||||
return response, err
|
||||
}
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
@ -1650,7 +1647,6 @@ func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool, config *param
|
|||
func (s *BlockChainAPI) rpcMarshalHeader(ctx context.Context, header *types.Header) map[string]interface{} {
|
||||
fields := RPCMarshalHeader(header)
|
||||
fields["totalDifficulty"] = (*hexutil.Big)(s.b.GetTd(ctx, header.Hash()))
|
||||
|
||||
return fields
|
||||
}
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -21,9 +21,8 @@ import (
|
|||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/golang-jwt/jwt/v4"
|
||||
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/golang-jwt/jwt/v4"
|
||||
)
|
||||
|
||||
// NewJWTAuth creates an rpc client authentication provider that uses JWT. The
|
||||
|
|
@ -36,14 +35,11 @@ func NewJWTAuth(jwtsecret [32]byte) rpc.HTTPAuth {
|
|||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
|
||||
"iat": &jwt.NumericDate{Time: time.Now()},
|
||||
})
|
||||
|
||||
s, err := token.SignedString(jwtsecret[:])
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create JWT token: %w", err)
|
||||
}
|
||||
|
||||
h.Set("Authorization", "Bearer "+s)
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue