Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions cmd/jsutils/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"semi": true,
"tabWidth": 4,
"printWidth": 160,
"singleQuote": false,
"trailingComma": "es5",
"bracketSpacing": true,
"arrowParens": "avoid",
"endOfLine": "lf"
}
803 changes: 446 additions & 357 deletions cmd/jsutils/getchainstatus.js

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions cmd/jsutils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
"main": "index.js",
"scripts": {
"startMainnet": "node getvalidatorversion.js --Rpc https://bsc-dataseed.bnbchain.org --Num 21",
"startTestnet": "node getvalidatorversion.js --Rpc https://bsc-testnet-dataseed.bnbchain.org --Num 7"
"startTestnet": "node getvalidatorversion.js --Rpc https://bsc-testnet-dataseed.bnbchain.org --Num 7",
"format": "prettier --write \"**/*.{js,jsx,ts,tsx}\""
},
"dependencies": {
"commander": "^3.0.1",
"ethers": "^6.2.3"
},
"author": "BNB Chain"
"author": "BNB Chain",
"devDependencies": {
"prettier": "^3.5.3"
}
}
5 changes: 1 addition & 4 deletions core/rawdb/chain_freezer.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,7 @@ func (f *chainFreezer) freezeThreshold(db ethdb.Reader) (uint64, error) {
if final == 0 && headLimit == 0 {
return 0, errors.New("freezing threshold is not available")
}
if final > headLimit {
return final, nil
}
return headLimit, nil
return max(final, headLimit), nil
}

// freeze is a background thread that periodically checks the blockchain for any
Expand Down
5 changes: 1 addition & 4 deletions core/txpool/blobpool/priority.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ func evictionPriority(basefeeJumps float64, txBasefeeJumps, blobfeeJumps, txBlob
basefeePriority = evictionPriority1D(basefeeJumps, txBasefeeJumps)
blobfeePriority = evictionPriority1D(blobfeeJumps, txBlobfeeJumps)
)
if basefeePriority < blobfeePriority {
return basefeePriority
}
return blobfeePriority
return min(basefeePriority, blobfeePriority)
}

// evictionPriority1D calculates the eviction priority based on the algorithm
Expand Down
15 changes: 3 additions & 12 deletions core/vm/memory_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ func memoryCall(stack *Stack) (uint64, bool) {
if overflow {
return 0, true
}
if x > y {
return x, false
}
return y, false
return max(x, y), false
}

func memoryDelegateCall(stack *Stack) (uint64, bool) {
Expand All @@ -88,10 +85,7 @@ func memoryDelegateCall(stack *Stack) (uint64, bool) {
if overflow {
return 0, true
}
if x > y {
return x, false
}
return y, false
return max(x, y), false
}

func memoryStaticCall(stack *Stack) (uint64, bool) {
Expand All @@ -103,10 +97,7 @@ func memoryStaticCall(stack *Stack) (uint64, bool) {
if overflow {
return 0, true
}
if x > y {
return x, false
}
return y, false
return max(x, y), false
}

func memoryReturn(stack *Stack) (uint64, bool) {
Expand Down
8 changes: 0 additions & 8 deletions eth/protocols/bsc/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@ const (
secondsPerPeriod = float64(30)
)

// max is a helper function which returns the larger of the two given integers.
func max(a, b int) int {
if a > b {
return a
}
return b
}

// Peer is a collection of relevant information we have about a `bsc` peer.
type Peer struct {
id string // Unique ID for the peer, cached
Expand Down
8 changes: 0 additions & 8 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@ import (
"github.com/holiman/uint256"
)

// max is a helper function which returns the larger of the two given integers.
func max(a, b int64) int64 {
if a > b {
return a
}
return b
}

const UnHealthyTimeout = 5 * time.Second

// estimateGasErrorRatio is the amount of overestimation eth_estimateGas is
Expand Down
48 changes: 17 additions & 31 deletions internal/web3ext/web3ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package web3ext

var Modules = map[string]string{
"admin": AdminJs,
"clique": CliqueJs,
"parlia": ParliaJs,
"debug": DebugJs,
"eth": EthJs,
"miner": MinerJs,
Expand All @@ -29,60 +29,46 @@ var Modules = map[string]string{
"dev": DevJs,
}

const CliqueJs = `
const ParliaJs = `
web3._extend({
property: 'clique',
property: 'parlia',
methods: [
new web3._extend.Method({
name: 'getSnapshot',
call: 'clique_getSnapshot',
call: 'parlia_getSnapshot',
params: 1,
inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter]
}),
new web3._extend.Method({
name: 'getSnapshotAtHash',
call: 'clique_getSnapshotAtHash',
call: 'parlia_getSnapshotAtHash',
params: 1
}),
new web3._extend.Method({
name: 'getSigners',
call: 'clique_getSigners',
name: 'getValidators',
call: 'parlia_getValidators',
params: 1,
inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter]
}),
new web3._extend.Method({
name: 'getSignersAtHash',
call: 'clique_getSignersAtHash',
name: 'getValidatorsAtHash',
call: 'parlia_getValidatorsAtHash',
params: 1
}),
new web3._extend.Method({
name: 'propose',
call: 'clique_propose',
params: 2
}),
new web3._extend.Method({
name: 'discard',
call: 'clique_discard',
params: 1
}),
new web3._extend.Method({
name: 'status',
call: 'clique_status',
params: 0
name: 'getJustifiedNumber',
call: 'parlia_getJustifiedNumber',
params: 1,
inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter]
}),
new web3._extend.Method({
name: 'getSigner',
call: 'clique_getSigner',
name: 'getFinalizedNumber',
call: 'parlia_getFinalizedNumber',
params: 1,
inputFormatter: [null]
inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter]
}),
],
properties: [
new web3._extend.Property({
name: 'proposals',
getter: 'clique_proposals'
}),
]
properties: []
});
`

Expand Down
52 changes: 28 additions & 24 deletions miner/bid_simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ import (
"github.com/ethereum/go-ethereum/rpc"
)

const (
// maxBidPerBuilderPerBlock is the max bid number per builder
maxBidPerBuilderPerBlock = 3
)

var (
bidSimTimer = metrics.NewRegisteredTimer("bid/sim/duration", nil)
)
Expand Down Expand Up @@ -118,6 +113,8 @@ type bidSimulator struct {

simBidMu sync.RWMutex
simulatingBid map[common.Hash]*BidRuntime // prevBlockHash -> bidRuntime, in the process of simulation

maxBidsPerBuilder uint32 // Maximum number of bids allowed per builder per block
}

func newBidSimulator(
Expand All @@ -129,24 +126,31 @@ func newBidSimulator(
engine consensus.Engine,
bidWorker bidWorker,
) *bidSimulator {
// Set default value
maxBids := uint32(3)
if config.MaxBidsPerBuilder > 0 {
maxBids = config.MaxBidsPerBuilder
}

b := &bidSimulator{
config: config,
delayLeftOver: delayLeftOver,
minGasPrice: minGasPrice,
chain: eth.BlockChain(),
txpool: eth.TxPool(),
chainConfig: chainConfig,
engine: engine,
bidWorker: bidWorker,
exitCh: make(chan struct{}),
chainHeadCh: make(chan core.ChainHeadEvent, chainHeadChanSize),
builders: make(map[common.Address]*builderclient.Client),
simBidCh: make(chan *simBidReq),
newBidCh: make(chan newBidPackage, 100),
pending: make(map[uint64]map[common.Address]map[common.Hash]struct{}),
bestBid: make(map[common.Hash]*BidRuntime),
bestBidToRun: make(map[common.Hash]*types.Bid),
simulatingBid: make(map[common.Hash]*BidRuntime),
config: config,
delayLeftOver: delayLeftOver,
minGasPrice: minGasPrice,
chain: eth.BlockChain(),
txpool: eth.TxPool(),
chainConfig: chainConfig,
engine: engine,
bidWorker: bidWorker,
maxBidsPerBuilder: maxBids,
exitCh: make(chan struct{}),
chainHeadCh: make(chan core.ChainHeadEvent, chainHeadChanSize),
builders: make(map[common.Address]*builderclient.Client),
simBidCh: make(chan *simBidReq),
newBidCh: make(chan newBidPackage, 100),
pending: make(map[uint64]map[common.Address]map[common.Hash]struct{}),
bestBid: make(map[common.Hash]*BidRuntime),
bestBidToRun: make(map[common.Hash]*types.Bid),
simulatingBid: make(map[common.Hash]*BidRuntime),
}

b.chainHeadSub = b.chain.SubscribeChainHeadEvent(b.chainHeadCh)
Expand Down Expand Up @@ -577,8 +581,8 @@ func (b *bidSimulator) CheckPending(blockNumber uint64, builder common.Address,
return errors.New("bid already exists")
}

if len(b.pending[blockNumber][builder]) >= maxBidPerBuilderPerBlock {
return errors.New("too many bids")
if len(b.pending[blockNumber][builder]) >= int(b.maxBidsPerBuilder) {
return fmt.Errorf("too many bids: exceeded limit of %d bids per builder per block", b.maxBidsPerBuilder)
}

return nil
Expand Down
2 changes: 2 additions & 0 deletions miner/minerconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type MevConfig struct {
ValidatorCommission uint64 // 100 means the validator claims 1% from block reward
BidSimulationLeftOver time.Duration
NoInterruptLeftOver time.Duration
MaxBidsPerBuilder uint32 // Maximum number of bids allowed per builder per block
}

var DefaultMevConfig = MevConfig{
Expand All @@ -86,4 +87,5 @@ var DefaultMevConfig = MevConfig{
ValidatorCommission: 100,
BidSimulationLeftOver: 50 * time.Millisecond,
NoInterruptLeftOver: 400 * time.Millisecond,
MaxBidsPerBuilder: 3,
}
9 changes: 0 additions & 9 deletions p2p/nat/stun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,8 @@ package nat

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestNatStun(t *testing.T) {
nat, err := newSTUN("")
assert.NoError(t, err)
_, err = nat.ExternalIP()
assert.NoError(t, err)
}

func TestUnreachedNatServer(t *testing.T) {
stun := &stun{
serverList: []string{"198.51.100.2:1234", "198.51.100.5"},
Expand Down