From 9b95339c383221a444f36b668d21691197aff6fd Mon Sep 17 00:00:00 2001 From: NathanBSC <122502194+NathanBSC@users.noreply.github.com> Date: Mon, 14 Aug 2023 17:48:36 +0800 Subject: [PATCH 1/4] vote: remove DisableBscProtocol and add flag to skip votes assmebling (#1805) --- cmd/geth/main.go | 2 +- cmd/geth/usage.go | 2 +- cmd/utils/flags.go | 15 ++++++++------- consensus/parlia/parlia.go | 2 +- eth/backend.go | 10 ++++++---- eth/ethconfig/config.go | 1 - eth/ethconfig/gen_config.go | 6 ------ miner/miner.go | 23 ++++++++++++----------- 8 files changed, 29 insertions(+), 32 deletions(-) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 08fbdd524e..bce4362e24 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -72,7 +72,6 @@ var ( utils.DisableSnapProtocolFlag, utils.DisableDiffProtocolFlag, utils.EnableTrustProtocolFlag, - utils.DisableBscProtocolFlag, utils.DiffSyncFlag, utils.PipeCommitFlag, utils.RangeLimitFlag, @@ -171,6 +170,7 @@ var ( utils.CheckSnapshotWithMPT, utils.EnableDoubleSignMonitorFlag, utils.VotingEnabledFlag, + utils.DisableVoteAttestationFlag, utils.EnableMaliciousVoteMonitorFlag, utils.BLSPasswordFileFlag, utils.BLSWalletDirFlag, diff --git a/cmd/geth/usage.go b/cmd/geth/usage.go index 690a2e8251..58ccaed14a 100644 --- a/cmd/geth/usage.go +++ b/cmd/geth/usage.go @@ -43,7 +43,6 @@ var AppHelpFlagGroups = []flags.FlagGroup{ utils.DisableSnapProtocolFlag, utils.DisableDiffProtocolFlag, utils.EnableTrustProtocolFlag, - utils.DisableBscProtocolFlag, utils.RangeLimitFlag, utils.SmartCardDaemonPathFlag, utils.NetworkIdFlag, @@ -201,6 +200,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{ utils.MinerDelayLeftoverFlag, utils.MinerNoVerfiyFlag, utils.VotingEnabledFlag, + utils.DisableVoteAttestationFlag, }, }, { diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 167b9f7a51..ea679b79a1 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -134,10 +134,6 @@ var ( Name: "enabletrustprotocol", Usage: "Enable trust protocol", } - DisableBscProtocolFlag = cli.BoolFlag{ - Name: "disablebscprotocol", - Usage: "Disable bsc protocol", - } DiffSyncFlag = cli.BoolFlag{ Name: "diffsync", @@ -908,6 +904,11 @@ var ( Usage: "Enable voting when mining", } + DisableVoteAttestationFlag = cli.BoolFlag{ + Name: "disablevoteattestation", + Usage: "Disable assembling vote attestation ", + } + EnableMaliciousVoteMonitorFlag = cli.BoolFlag{ Name: "monitor.maliciousvote", Usage: "Enable malicious vote monitor to check whether any validator violates the voting rules of fast finality", @@ -1562,6 +1563,9 @@ func setMiner(ctx *cli.Context, cfg *miner.Config) { if ctx.GlobalBool(VotingEnabledFlag.Name) { cfg.VoteEnable = true } + if ctx.GlobalBool(DisableVoteAttestationFlag.Name) { + cfg.DisableVoteAttestation = true + } } func setWhitelist(ctx *cli.Context, cfg *ethconfig.Config) { @@ -1720,9 +1724,6 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { if ctx.GlobalIsSet(EnableTrustProtocolFlag.Name) { cfg.EnableTrustProtocol = ctx.GlobalIsSet(EnableTrustProtocolFlag.Name) } - if ctx.GlobalIsSet(DisableBscProtocolFlag.Name) { - cfg.DisableBscProtocol = ctx.GlobalIsSet(DisableBscProtocolFlag.Name) - } if ctx.GlobalIsSet(DiffSyncFlag.Name) { log.Warn("The --diffsync flag is deprecated and will be removed in the future!") } diff --git a/consensus/parlia/parlia.go b/consensus/parlia/parlia.go index 3ea1591c1c..7269b490ee 100644 --- a/consensus/parlia/parlia.go +++ b/consensus/parlia/parlia.go @@ -827,7 +827,7 @@ func (p *Parlia) assembleVoteAttestation(chain consensus.ChainHeaderReader, head } if p.VotePool == nil { - return errors.New("vote pool is nil") + return nil } // Fetch direct parent's votes diff --git a/eth/backend.go b/eth/backend.go index e4b0e0ae98..60d95ac188 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -284,7 +284,10 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { votePool := vote.NewVotePool(chainConfig, eth.blockchain, posa) eth.votePool = votePool if parlia, ok := eth.engine.(*parlia.Parlia); ok { - parlia.VotePool = votePool + if !config.Miner.DisableVoteAttestation { + // if there is no VotePool in Parlia Engine, the miner can't get votes for assembling + parlia.VotePool = votePool + } } else { return nil, fmt.Errorf("Engine is not Parlia type") } @@ -627,9 +630,8 @@ func (s *Ethereum) Protocols() []p2p.Protocol { if s.config.EnableTrustProtocol { protos = append(protos, trust.MakeProtocols((*trustHandler)(s.handler), s.snapDialCandidates)...) } - if !s.config.DisableBscProtocol { - protos = append(protos, bsc.MakeProtocols((*bscHandler)(s.handler), s.bscDialCandidates)...) - } + protos = append(protos, bsc.MakeProtocols((*bscHandler)(s.handler), s.bscDialCandidates)...) + return protos } diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index 29bb597410..de44234fbc 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -151,7 +151,6 @@ type Config struct { DisableSnapProtocol bool //Whether disable snap protocol DisableDiffProtocol bool //Whether disable diff protocol EnableTrustProtocol bool //Whether enable trust protocol - DisableBscProtocol bool //Whether disable bsc protocol DiffSync bool // Whether support diff sync PipeCommit bool RangeLimit bool diff --git a/eth/ethconfig/gen_config.go b/eth/ethconfig/gen_config.go index 13891c04c9..cf0d8f094d 100644 --- a/eth/ethconfig/gen_config.go +++ b/eth/ethconfig/gen_config.go @@ -32,7 +32,6 @@ func (c Config) MarshalTOML() (interface{}, error) { DisableSnapProtocol bool DisableDiffProtocol bool EnableTrustProtocol bool - DisableBscProtocol bool DiffSync bool RangeLimit bool TxLookupLimit uint64 `toml:",omitempty"` @@ -95,7 +94,6 @@ func (c Config) MarshalTOML() (interface{}, error) { enc.DisableSnapProtocol = c.DisableSnapProtocol enc.DisableDiffProtocol = c.DisableDiffProtocol enc.EnableTrustProtocol = c.EnableTrustProtocol - enc.DisableBscProtocol = c.DisableBscProtocol enc.DiffSync = c.DiffSync enc.RangeLimit = c.RangeLimit enc.TxLookupLimit = c.TxLookupLimit @@ -163,7 +161,6 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { DisableSnapProtocol *bool DisableDiffProtocol *bool EnableTrustProtocol *bool - DisableBscProtocol *bool DiffSync *bool RangeLimit *bool TxLookupLimit *uint64 `toml:",omitempty"` @@ -255,9 +252,6 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { if dec.EnableTrustProtocol != nil { c.EnableTrustProtocol = *dec.EnableTrustProtocol } - if dec.DisableBscProtocol != nil { - c.DisableBscProtocol = *dec.DisableBscProtocol - } if dec.DiffSync != nil { c.DiffSync = *dec.DiffSync } diff --git a/miner/miner.go b/miner/miner.go index 3d355bca05..060ef2df4b 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -44,17 +44,18 @@ type Backend interface { // Config is the configuration parameters of mining. type Config struct { - Etherbase common.Address `toml:",omitempty"` // Public address for block mining rewards (default = first account) - Notify []string `toml:",omitempty"` // HTTP URL list to be notified of new work packages (only useful in ethash). - NotifyFull bool `toml:",omitempty"` // Notify with pending block headers instead of work packages - ExtraData hexutil.Bytes `toml:",omitempty"` // Block extra data set by the miner - DelayLeftOver time.Duration // Time reserved to finalize a block(calculate root, distribute income...) - GasFloor uint64 // Target gas floor for mined blocks. - GasCeil uint64 // Target gas ceiling for mined blocks. - GasPrice *big.Int // Minimum gas price for mining a transaction - Recommit time.Duration // The time interval for miner to re-create mining work. - Noverify bool // Disable remote mining solution verification(only useful in ethash). - VoteEnable bool // Whether to vote when mining + Etherbase common.Address `toml:",omitempty"` // Public address for block mining rewards (default = first account) + Notify []string `toml:",omitempty"` // HTTP URL list to be notified of new work packages (only useful in ethash). + NotifyFull bool `toml:",omitempty"` // Notify with pending block headers instead of work packages + ExtraData hexutil.Bytes `toml:",omitempty"` // Block extra data set by the miner + DelayLeftOver time.Duration // Time reserved to finalize a block(calculate root, distribute income...) + GasFloor uint64 // Target gas floor for mined blocks. + GasCeil uint64 // Target gas ceiling for mined blocks. + GasPrice *big.Int // Minimum gas price for mining a transaction + Recommit time.Duration // The time interval for miner to re-create mining work. + Noverify bool // Disable remote mining solution verification(only useful in ethash). + VoteEnable bool // Whether to vote when mining + DisableVoteAttestation bool // Whether to skip assembling vote attestation } // Miner creates blocks and searches for proof-of-work values. From 0bc5a2a2d7f146ecb13181ea5d12e61234fc4c06 Mon Sep 17 00:00:00 2001 From: NathanBSC <122502194+NathanBSC@users.noreply.github.com> Date: Tue, 15 Aug 2023 11:40:52 +0800 Subject: [PATCH 2/4] client: add FinalizedHeader/Block to use the fast finality (#1797) --- ethclient/ethclient.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index 745a371e6a..ebcbc5f5c1 100644 --- a/ethclient/ethclient.go +++ b/ethclient/ethclient.go @@ -188,6 +188,27 @@ func (ec *Client) HeaderByNumber(ctx context.Context, number *big.Int) (*types.H return head, err } +// GetFinalizedHeader returns the requested finalized block header. +// - probabilisticFinalized should be in range [2,21], +// then the block header with number `max(fastFinalized, latest-probabilisticFinalized)` is returned +func (ec *Client) FinalizedHeader(ctx context.Context, probabilisticFinalized int64) (*types.Header, error) { + var head *types.Header + err := ec.c.CallContext(ctx, &head, "eth_getFinalizedHeader", probabilisticFinalized) + if err == nil && head == nil { + err = ethereum.NotFound + } + return head, err +} + +// GetFinalizedBlock returns the requested finalized block. +// - probabilisticFinalized should be in range [2,21], +// then the block with number `max(fastFinalized, latest-probabilisticFinalized)` is returned +// - When fullTx is true all transactions in the block are returned, otherwise +// only the transaction hash is returned. +func (ec *Client) FinalizedBlock(ctx context.Context, probabilisticFinalized int64, fullTx bool) (*types.Block, error) { + return ec.getBlock(ctx, "eth_getFinalizedBlock", probabilisticFinalized, true) +} + // GetDiffAccounts returns changed accounts in a specific block number. func (ec *Client) GetDiffAccounts(ctx context.Context, number *big.Int) ([]common.Address, error) { accounts := make([]common.Address, 0) From e2bf0f3fbd2ba71b42130daf26b42c4243806d0d Mon Sep 17 00:00:00 2001 From: lx <92799281+brilliant-lx@users.noreply.github.com> Date: Mon, 21 Aug 2023 10:31:18 +0800 Subject: [PATCH 3/4] fix: lagging nodes failed to sync (#1829) FastFinality puts more infor into the header.extra field to keep vote information. For mainnet, on epoch height, it could be 1526 bytes, which was 517 bytes before. So the hardcoded 700 bytes for header could be no longer enough, increase it by 2 times would be enough. this bug could cause P2P sync failure for nodes that are lagging behind, since they would request access of ancient db, and GetBlockHeaders could be failed. --- core/rawdb/accessors_chain.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/rawdb/accessors_chain.go b/core/rawdb/accessors_chain.go index 690536cd5d..6b6af68bb7 100644 --- a/core/rawdb/accessors_chain.go +++ b/core/rawdb/accessors_chain.go @@ -318,7 +318,7 @@ func ReadHeaderRange(db ethdb.Reader, number uint64, count uint64) []rlp.RawValu return rlpHeaders } // read remaining from ancients - max := count * 700 + max := count * 700 * 3 data, err := db.AncientRange(freezerHeaderTable, i+1-count, count, max) if err == nil && uint64(len(data)) == count { // the data is on the order [h, h+1, .., n] -- reordering needed From c035b0c8166b89c18911a998dcebbc51614b6e33 Mon Sep 17 00:00:00 2001 From: lx <92799281+brilliant-lx@users.noreply.github.com> Date: Tue, 22 Aug 2023 11:10:53 +0800 Subject: [PATCH 4/4] release: prepare for release v1.2.11 (#1832) --- CHANGELOG.md | 9 +++++++++ params/version.go | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d67cb0026..7d628cdbcf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,19 @@ # Changelog +## v1.2.11 +FEATURE +* [\#1797](https://github.com/bnb-chain/bsc/pull/1797) client: add FinalizedHeader/Block to use the fast finality +* [\#1805](https://github.com/bnb-chain/bsc/pull/1805) vote: remove DisableBscProtocol and add flag to skip votes assmebling + +BUGFIX +* [\#1829](https://github.com/bnb-chain/bsc/pull/1829) fix: lagging nodes failed to sync + ## v1.2.10 FEATURE * [\#1780](https://github.com/bnb-chain/bsc/pull/1780) log: reduce logs when receiving too much votes from a peer * [\#1788](https://github.com/bnb-chain/bsc/pull/1788) metrics: add txpool config into metrics server * [\#1789](https://github.com/bnb-chain/bsc/pull/1789) rpc: add GetFinalizedHeader/Block to simplify using the fast finality feature * [\#1791](https://github.com/bnb-chain/bsc/pull/1791) finality: add more check to ensure result of assembleVoteAttestation +* [\#1795](https://github.com/bnb-chain/bsc/pull/1795) tool: add a tool extradump to parse extra data after luban BUGFIX * [\#1773](https://github.com/bnb-chain/bsc/pull/1773) discov: do not filter out bootnodes diff --git a/params/version.go b/params/version.go index 4fa6fe41f8..78a85e7323 100644 --- a/params/version.go +++ b/params/version.go @@ -23,7 +23,7 @@ import ( const ( VersionMajor = 1 // Major version component of the current release VersionMinor = 2 // Minor version component of the current release - VersionPatch = 10 // Patch version component of the current release + VersionPatch = 11 // Patch version component of the current release VersionMeta = "" // Version metadata to append to the version string )