Skip to content

Commit b970c01

Browse files
authored
Merge: from develop to master branch for v1.5.9 (bnb-chain#3003)
2 parents 2ccdf1a + f9dc640 commit b970c01

File tree

12 files changed

+514
-459
lines changed

12 files changed

+514
-459
lines changed

cmd/jsutils/.prettierrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"semi": true,
3+
"tabWidth": 4,
4+
"printWidth": 160,
5+
"singleQuote": false,
6+
"trailingComma": "es5",
7+
"bracketSpacing": true,
8+
"arrowParens": "avoid",
9+
"endOfLine": "lf"
10+
}

cmd/jsutils/getchainstatus.js

Lines changed: 446 additions & 357 deletions
Large diffs are not rendered by default.

cmd/jsutils/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66
"main": "index.js",
77
"scripts": {
88
"startMainnet": "node getvalidatorversion.js --Rpc https://bsc-dataseed.bnbchain.org --Num 21",
9-
"startTestnet": "node getvalidatorversion.js --Rpc https://bsc-testnet-dataseed.bnbchain.org --Num 7"
9+
"startTestnet": "node getvalidatorversion.js --Rpc https://bsc-testnet-dataseed.bnbchain.org --Num 7",
10+
"format": "prettier --write \"**/*.{js,jsx,ts,tsx}\""
1011
},
1112
"dependencies": {
1213
"commander": "^3.0.1",
1314
"ethers": "^6.2.3"
1415
},
15-
"author": "BNB Chain"
16+
"author": "BNB Chain",
17+
"devDependencies": {
18+
"prettier": "^3.5.3"
19+
}
1620
}

core/rawdb/chain_freezer.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,7 @@ func (f *chainFreezer) freezeThreshold(db ethdb.Reader) (uint64, error) {
152152
if final == 0 && headLimit == 0 {
153153
return 0, errors.New("freezing threshold is not available")
154154
}
155-
if final > headLimit {
156-
return final, nil
157-
}
158-
return headLimit, nil
155+
return max(final, headLimit), nil
159156
}
160157

161158
// freeze is a background thread that periodically checks the blockchain for any

core/txpool/blobpool/priority.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ func evictionPriority(basefeeJumps float64, txBasefeeJumps, blobfeeJumps, txBlob
3636
basefeePriority = evictionPriority1D(basefeeJumps, txBasefeeJumps)
3737
blobfeePriority = evictionPriority1D(blobfeeJumps, txBlobfeeJumps)
3838
)
39-
if basefeePriority < blobfeePriority {
40-
return basefeePriority
41-
}
42-
return blobfeePriority
39+
return min(basefeePriority, blobfeePriority)
4340
}
4441

4542
// evictionPriority1D calculates the eviction priority based on the algorithm

core/vm/memory_table.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,7 @@ func memoryCall(stack *Stack) (uint64, bool) {
7373
if overflow {
7474
return 0, true
7575
}
76-
if x > y {
77-
return x, false
78-
}
79-
return y, false
76+
return max(x, y), false
8077
}
8178

8279
func memoryDelegateCall(stack *Stack) (uint64, bool) {
@@ -88,10 +85,7 @@ func memoryDelegateCall(stack *Stack) (uint64, bool) {
8885
if overflow {
8986
return 0, true
9087
}
91-
if x > y {
92-
return x, false
93-
}
94-
return y, false
88+
return max(x, y), false
9589
}
9690

9791
func memoryStaticCall(stack *Stack) (uint64, bool) {
@@ -103,10 +97,7 @@ func memoryStaticCall(stack *Stack) (uint64, bool) {
10397
if overflow {
10498
return 0, true
10599
}
106-
if x > y {
107-
return x, false
108-
}
109-
return y, false
100+
return max(x, y), false
110101
}
111102

112103
func memoryReturn(stack *Stack) (uint64, bool) {

eth/protocols/bsc/peer.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@ const (
2828
secondsPerPeriod = float64(30)
2929
)
3030

31-
// max is a helper function which returns the larger of the two given integers.
32-
func max(a, b int) int {
33-
if a > b {
34-
return a
35-
}
36-
return b
37-
}
38-
3931
// Peer is a collection of relevant information we have about a `bsc` peer.
4032
type Peer struct {
4133
id string // Unique ID for the peer, cached

internal/ethapi/api.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,6 @@ import (
5454
"github.com/holiman/uint256"
5555
)
5656

57-
// max is a helper function which returns the larger of the two given integers.
58-
func max(a, b int64) int64 {
59-
if a > b {
60-
return a
61-
}
62-
return b
63-
}
64-
6557
const UnHealthyTimeout = 5 * time.Second
6658

6759
// estimateGasErrorRatio is the amount of overestimation eth_estimateGas is

internal/web3ext/web3ext.go

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package web3ext
1919

2020
var Modules = map[string]string{
2121
"admin": AdminJs,
22-
"clique": CliqueJs,
22+
"parlia": ParliaJs,
2323
"debug": DebugJs,
2424
"eth": EthJs,
2525
"miner": MinerJs,
@@ -29,60 +29,46 @@ var Modules = map[string]string{
2929
"dev": DevJs,
3030
}
3131

32-
const CliqueJs = `
32+
const ParliaJs = `
3333
web3._extend({
34-
property: 'clique',
34+
property: 'parlia',
3535
methods: [
3636
new web3._extend.Method({
3737
name: 'getSnapshot',
38-
call: 'clique_getSnapshot',
38+
call: 'parlia_getSnapshot',
3939
params: 1,
4040
inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter]
4141
}),
4242
new web3._extend.Method({
4343
name: 'getSnapshotAtHash',
44-
call: 'clique_getSnapshotAtHash',
44+
call: 'parlia_getSnapshotAtHash',
4545
params: 1
4646
}),
4747
new web3._extend.Method({
48-
name: 'getSigners',
49-
call: 'clique_getSigners',
48+
name: 'getValidators',
49+
call: 'parlia_getValidators',
5050
params: 1,
5151
inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter]
5252
}),
5353
new web3._extend.Method({
54-
name: 'getSignersAtHash',
55-
call: 'clique_getSignersAtHash',
54+
name: 'getValidatorsAtHash',
55+
call: 'parlia_getValidatorsAtHash',
5656
params: 1
5757
}),
5858
new web3._extend.Method({
59-
name: 'propose',
60-
call: 'clique_propose',
61-
params: 2
62-
}),
63-
new web3._extend.Method({
64-
name: 'discard',
65-
call: 'clique_discard',
66-
params: 1
67-
}),
68-
new web3._extend.Method({
69-
name: 'status',
70-
call: 'clique_status',
71-
params: 0
59+
name: 'getJustifiedNumber',
60+
call: 'parlia_getJustifiedNumber',
61+
params: 1,
62+
inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter]
7263
}),
7364
new web3._extend.Method({
74-
name: 'getSigner',
75-
call: 'clique_getSigner',
65+
name: 'getFinalizedNumber',
66+
call: 'parlia_getFinalizedNumber',
7667
params: 1,
77-
inputFormatter: [null]
68+
inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter]
7869
}),
7970
],
80-
properties: [
81-
new web3._extend.Property({
82-
name: 'proposals',
83-
getter: 'clique_proposals'
84-
}),
85-
]
71+
properties: []
8672
});
8773
`
8874

miner/bid_simulator.go

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ import (
3131
"github.com/ethereum/go-ethereum/rpc"
3232
)
3333

34-
const (
35-
// maxBidPerBuilderPerBlock is the max bid number per builder
36-
maxBidPerBuilderPerBlock = 3
37-
)
38-
3934
var (
4035
bidSimTimer = metrics.NewRegisteredTimer("bid/sim/duration", nil)
4136
)
@@ -118,6 +113,8 @@ type bidSimulator struct {
118113

119114
simBidMu sync.RWMutex
120115
simulatingBid map[common.Hash]*BidRuntime // prevBlockHash -> bidRuntime, in the process of simulation
116+
117+
maxBidsPerBuilder uint32 // Maximum number of bids allowed per builder per block
121118
}
122119

123120
func newBidSimulator(
@@ -129,24 +126,31 @@ func newBidSimulator(
129126
engine consensus.Engine,
130127
bidWorker bidWorker,
131128
) *bidSimulator {
129+
// Set default value
130+
maxBids := uint32(3)
131+
if config.MaxBidsPerBuilder > 0 {
132+
maxBids = config.MaxBidsPerBuilder
133+
}
134+
132135
b := &bidSimulator{
133-
config: config,
134-
delayLeftOver: delayLeftOver,
135-
minGasPrice: minGasPrice,
136-
chain: eth.BlockChain(),
137-
txpool: eth.TxPool(),
138-
chainConfig: chainConfig,
139-
engine: engine,
140-
bidWorker: bidWorker,
141-
exitCh: make(chan struct{}),
142-
chainHeadCh: make(chan core.ChainHeadEvent, chainHeadChanSize),
143-
builders: make(map[common.Address]*builderclient.Client),
144-
simBidCh: make(chan *simBidReq),
145-
newBidCh: make(chan newBidPackage, 100),
146-
pending: make(map[uint64]map[common.Address]map[common.Hash]struct{}),
147-
bestBid: make(map[common.Hash]*BidRuntime),
148-
bestBidToRun: make(map[common.Hash]*types.Bid),
149-
simulatingBid: make(map[common.Hash]*BidRuntime),
136+
config: config,
137+
delayLeftOver: delayLeftOver,
138+
minGasPrice: minGasPrice,
139+
chain: eth.BlockChain(),
140+
txpool: eth.TxPool(),
141+
chainConfig: chainConfig,
142+
engine: engine,
143+
bidWorker: bidWorker,
144+
maxBidsPerBuilder: maxBids,
145+
exitCh: make(chan struct{}),
146+
chainHeadCh: make(chan core.ChainHeadEvent, chainHeadChanSize),
147+
builders: make(map[common.Address]*builderclient.Client),
148+
simBidCh: make(chan *simBidReq),
149+
newBidCh: make(chan newBidPackage, 100),
150+
pending: make(map[uint64]map[common.Address]map[common.Hash]struct{}),
151+
bestBid: make(map[common.Hash]*BidRuntime),
152+
bestBidToRun: make(map[common.Hash]*types.Bid),
153+
simulatingBid: make(map[common.Hash]*BidRuntime),
150154
}
151155

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

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

584588
return nil

0 commit comments

Comments
 (0)