From 5322ddf3fe9ba575b3ca80d73166d93a8a9baa72 Mon Sep 17 00:00:00 2001 From: qybdyx Date: Thu, 10 Oct 2024 11:22:16 +0800 Subject: [PATCH 1/3] concensus/parlia.go: make distribute incoming tx more independence --- consensus/parlia/parlia.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/consensus/parlia/parlia.go b/consensus/parlia/parlia.go index 79ff3f93af..ac49c33e78 100644 --- a/consensus/parlia/parlia.go +++ b/consensus/parlia/parlia.go @@ -1810,24 +1810,26 @@ func (p *Parlia) distributeIncoming(val common.Address, state *state.StateDB, he if balance.Cmp(common.U2560) <= 0 { return nil } - state.SetBalance(consensus.SystemAddress, common.U2560) - state.AddBalance(coinbase, balance) doDistributeSysReward := !p.chainConfig.IsKepler(header.Number, header.Time) && state.GetBalance(common.HexToAddress(systemcontracts.SystemRewardContract)).Cmp(maxSystemBalance) < 0 if doDistributeSysReward { rewards := new(uint256.Int) rewards = rewards.Rsh(balance, systemRewardPercent) + state.SetBalance(consensus.SystemAddress, balance.Sub(balance, rewards)) + state.AddBalance(coinbase, rewards) if rewards.Cmp(common.U2560) > 0 { err := p.distributeToSystem(rewards.ToBig(), state, header, chain, txs, receipts, receivedTxs, usedGas, mining) if err != nil { return err } log.Trace("distribute to system reward pool", "block hash", header.Hash(), "amount", rewards) - balance = balance.Sub(balance, rewards) } } log.Trace("distribute to validator contract", "block hash", header.Hash(), "amount", balance) + + state.AddBalance(coinbase, state.GetBalance(consensus.SystemAddress)) + state.SetBalance(consensus.SystemAddress, common.U2560) return p.distributeToValidator(balance.ToBig(), val, state, header, chain, txs, receipts, receivedTxs, usedGas, mining) } From e86af0b64016d1fb734530832f8592a988ac19fd Mon Sep 17 00:00:00 2001 From: qybdyx Date: Thu, 10 Oct 2024 12:14:33 +0800 Subject: [PATCH 2/3] concensus/parlia.go: make distribute incoming tx more independence --- consensus/parlia/parlia.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/consensus/parlia/parlia.go b/consensus/parlia/parlia.go index ac49c33e78..ba6e2ed04d 100644 --- a/consensus/parlia/parlia.go +++ b/consensus/parlia/parlia.go @@ -1816,14 +1816,15 @@ func (p *Parlia) distributeIncoming(val common.Address, state *state.StateDB, he if doDistributeSysReward { rewards := new(uint256.Int) rewards = rewards.Rsh(balance, systemRewardPercent) - state.SetBalance(consensus.SystemAddress, balance.Sub(balance, rewards)) - state.AddBalance(coinbase, rewards) if rewards.Cmp(common.U2560) > 0 { + state.SetBalance(consensus.SystemAddress, balance.Sub(balance, rewards)) + state.AddBalance(coinbase, rewards) err := p.distributeToSystem(rewards.ToBig(), state, header, chain, txs, receipts, receivedTxs, usedGas, mining) if err != nil { return err } log.Trace("distribute to system reward pool", "block hash", header.Hash(), "amount", rewards) + balance = balance.Sub(balance, rewards) } } log.Trace("distribute to validator contract", "block hash", header.Hash(), "amount", balance) From 298c26d5a954afd7738e82d7c6695b271a24b9e6 Mon Sep 17 00:00:00 2001 From: buddh0 Date: Thu, 10 Oct 2024 13:37:37 +0800 Subject: [PATCH 3/3] concensus/parlia.go: make distribute incoming tx more independence --- consensus/parlia/parlia.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/consensus/parlia/parlia.go b/consensus/parlia/parlia.go index ba6e2ed04d..a06067b25b 100644 --- a/consensus/parlia/parlia.go +++ b/consensus/parlia/parlia.go @@ -1806,14 +1806,11 @@ func (p *Parlia) getCurrentValidators(blockHash common.Hash, blockNum *big.Int) func (p *Parlia) distributeIncoming(val common.Address, state *state.StateDB, header *types.Header, chain core.ChainContext, txs *[]*types.Transaction, receipts *[]*types.Receipt, receivedTxs *[]*types.Transaction, usedGas *uint64, mining bool) error { coinbase := header.Coinbase - balance := state.GetBalance(consensus.SystemAddress) - if balance.Cmp(common.U2560) <= 0 { - return nil - } doDistributeSysReward := !p.chainConfig.IsKepler(header.Number, header.Time) && state.GetBalance(common.HexToAddress(systemcontracts.SystemRewardContract)).Cmp(maxSystemBalance) < 0 if doDistributeSysReward { + balance := state.GetBalance(consensus.SystemAddress) rewards := new(uint256.Int) rewards = rewards.Rsh(balance, systemRewardPercent) if rewards.Cmp(common.U2560) > 0 { @@ -1824,13 +1821,16 @@ func (p *Parlia) distributeIncoming(val common.Address, state *state.StateDB, he return err } log.Trace("distribute to system reward pool", "block hash", header.Hash(), "amount", rewards) - balance = balance.Sub(balance, rewards) } } - log.Trace("distribute to validator contract", "block hash", header.Hash(), "amount", balance) - state.AddBalance(coinbase, state.GetBalance(consensus.SystemAddress)) + balance := state.GetBalance(consensus.SystemAddress) + if balance.Cmp(common.U2560) <= 0 { + return nil + } state.SetBalance(consensus.SystemAddress, common.U2560) + state.AddBalance(coinbase, balance) + log.Trace("distribute to validator contract", "block hash", header.Hash(), "amount", balance) return p.distributeToValidator(balance.ToBig(), val, state, header, chain, txs, receipts, receivedTxs, usedGas, mining) }