Skip to content

Commit

Permalink
add log
Browse files Browse the repository at this point in the history
  • Loading branch information
blxdyx committed Oct 11, 2024
1 parent 2231d05 commit 8c02cd1
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions consensus/parlia/parlia.go
Original file line number Diff line number Diff line change
Expand Up @@ -1413,29 +1413,26 @@ func (p *Parlia) initContract(state *state.IntraBlockState, header *types.Header
return false, nil
}

func (p *Parlia) distributeToSystem(val libcommon.Address, state *state.IntraBlockState, header *types.Header,
func (p *Parlia) distributeToSystem(val libcommon.Address, ibs *state.IntraBlockState, header *types.Header,
txs *types.Transactions, receipts *types.Receipts, systemTxs *types.Transactions,
usedGas *uint64, mining bool, systemTxCall consensus.SystemTxCall, curIndex, txIndex *int) (bool, error) {
if *curIndex == *txIndex {
balance := state.GetBalance(consensus.SystemAddress).Clone()
if header.Number.Uint64() == 66 {
log.Info("balance", "bal", balance.Uint64())
}
balance := ibs.GetBalance(consensus.SystemAddress).Clone()
if balance.Cmp(u256.Num0) <= 0 {
return false, nil
}
doDistributeSysReward := !p.chainConfig.IsKepler(header.Number.Uint64(), header.Time) &&
state.GetBalance(systemcontracts.SystemRewardContract).Cmp(maxSystemBalance) < 0
ibs.GetBalance(systemcontracts.SystemRewardContract).Cmp(maxSystemBalance) < 0
if doDistributeSysReward {
rewards := new(uint256.Int)
rewards = rewards.Rsh(balance, systemRewardPercent)
if header.Number.Uint64() == 66 {
log.Info("rewards", "rew", rewards.Uint64())
if _, ok := ibs.StateReader.(*state.HistoryReaderV3); ok {
rewards = (*txs)[*curIndex].GetValue()
}
state.SetBalance(consensus.SystemAddress, balance.Sub(balance, rewards), tracing.BalanceDecreaseGasBuy)
state.AddBalance(val, rewards, tracing.BalanceDecreaseGasBuy)
ibs.SetBalance(consensus.SystemAddress, balance.Sub(balance, rewards), tracing.BalanceDecreaseGasBuy)
ibs.AddBalance(val, rewards, tracing.BalanceDecreaseGasBuy)
if rewards.Cmp(u256.Num0) > 0 {
return p.applyTransaction(val, systemcontracts.SystemRewardContract, rewards, nil, state, header,
return p.applyTransaction(val, systemcontracts.SystemRewardContract, rewards, nil, ibs, header,
txs, receipts, systemTxs, usedGas, mining, systemTxCall, curIndex)
}
}
Expand All @@ -1446,20 +1443,20 @@ func (p *Parlia) distributeToSystem(val libcommon.Address, state *state.IntraBlo
}

// distributeToValidator deposits validator reward to validator contract
func (p *Parlia) distributeToValidator(val libcommon.Address, state *state.IntraBlockState, header *types.Header,
func (p *Parlia) distributeToValidator(val libcommon.Address, ibs *state.IntraBlockState, header *types.Header,
txs *types.Transactions, receipts *types.Receipts, systemTxs *types.Transactions,
usedGas *uint64, mining bool, systemTxCall consensus.SystemTxCall, curIndex, txIndex *int) (bool, error) {

if *curIndex == *txIndex {
balance := state.GetBalance(consensus.SystemAddress).Clone()
if header.Number.Uint64() == 66 {
log.Info("balance", "bal", balance.Uint64())
balance := ibs.GetBalance(consensus.SystemAddress).Clone()
if _, ok := ibs.StateReader.(*state.HistoryReaderV3); ok {
balance = (*txs)[*curIndex].GetValue()
}
if balance.Cmp(u256.Num0) <= 0 {
return false, nil
}
state.SetBalance(consensus.SystemAddress, u256.Num0, tracing.BalanceDecreaseGasBuy)
state.AddBalance(val, balance, tracing.BalanceDecreaseGasBuy)
ibs.SetBalance(consensus.SystemAddress, u256.Num0, tracing.BalanceDecreaseGasBuy)
ibs.AddBalance(val, balance, tracing.BalanceDecreaseGasBuy)
// method
method := "deposit"

Expand All @@ -1472,7 +1469,7 @@ func (p *Parlia) distributeToValidator(val libcommon.Address, state *state.Intra
return true, err
}
// apply message
return p.applyTransaction(val, systemcontracts.ValidatorContract, balance, data, state, header, txs, receipts, systemTxs, usedGas, mining, systemTxCall, curIndex)
return p.applyTransaction(val, systemcontracts.ValidatorContract, balance, data, ibs, header, txs, receipts, systemTxs, usedGas, mining, systemTxCall, curIndex)
}
*curIndex++
return false, nil
Expand Down

0 comments on commit 8c02cd1

Please sign in to comment.