Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(parlia): clean up applying of internal transactions #325

Merged
merged 1 commit into from
Apr 26, 2024
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
31 changes: 14 additions & 17 deletions consensus/parlia/feynmanfork.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package parlia
import (
"container/heap"
"fmt"
"math/big"

"github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/common/hexutility"
"github.com/ledgerwatch/erigon/common/u256"
Expand All @@ -11,7 +13,6 @@ import (
"github.com/ledgerwatch/erigon/core/systemcontracts"
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/log/v3"
"math/big"
)

const SecondsPerDay uint64 = 86400
Expand All @@ -27,8 +28,8 @@ func isBreatheBlock(lastBlockTime, blockTime uint64) bool {

// initializeFeynmanContract initialize new contracts of Feynman fork
func (p *Parlia) initializeFeynmanContract(state *state.IntraBlockState, header *types.Header,
txs types.Transactions, receipts types.Receipts, systemTxs types.Transactions, usedGas *uint64, mining bool,
) (types.Transactions, types.Transactions, types.Receipts, error) {
txs *types.Transactions, receipts *types.Receipts, systemTxs *types.Transactions, usedGas *uint64, mining bool,
) error {
// method
method := "initialize"

Expand All @@ -44,20 +45,16 @@ func (p *Parlia) initializeFeynmanContract(state *state.IntraBlockState, header
data, err := p.stakeHubABI.Pack(method)
if err != nil {
log.Error("Unable to pack tx for initialize feynman contracts", "error", err)
return nil, nil, nil, err
return err
}
for _, c := range contracts {
// apply message
log.Info("initialize feynman contract", "block number", header.Number.Uint64(), "contract", c)
var tx types.Transaction
var receipt *types.Receipt
if systemTxs, tx, receipt, err = p.applyTransaction(header.Coinbase, c, u256.Num0, data, state, header, len(txs), systemTxs, usedGas, mining); err != nil {
return nil, nil, nil, err
if err := p.applyTransaction(header.Coinbase, c, u256.Num0, data, state, header, txs, receipts, systemTxs, usedGas, mining); err != nil {
return err
}
txs = append(txs, tx)
receipts = append(receipts, receipt)
}
return txs, systemTxs, receipts, nil
return nil
}

type ValidatorItem struct {
Expand Down Expand Up @@ -95,17 +92,17 @@ func (h *ValidatorHeap) Pop() interface{} {
}

func (p *Parlia) updateValidatorSetV2(chain consensus.ChainHeaderReader, state *state.IntraBlockState, header *types.Header,
txs types.Transactions, systemTxs types.Transactions, usedGas *uint64, mining bool,
) (types.Transactions, types.Transaction, *types.Receipt, error) {
txs *types.Transactions, receipts *types.Receipts, systemTxs *types.Transactions, usedGas *uint64, mining bool,
) error {
// 1. get all validators and its voting header.Nu power
parent := chain.GetHeader(header.ParentHash, header.Number.Uint64()-1)
validatorItems, err := p.getValidatorElectionInfo(parent, state)
if err != nil {
return nil, nil, nil, err
return err
}
maxElectedValidators, err := p.getMaxElectedValidators(parent, state)
if err != nil {
return nil, nil, nil, err
return err
}

// 2. sort by voting power
Expand All @@ -116,11 +113,11 @@ func (p *Parlia) updateValidatorSetV2(chain consensus.ChainHeaderReader, state *
data, err := p.validatorSetABI.Pack(method, eValidators, eVotingPowers, eVoteAddrs)
if err != nil {
log.Error("Unable to pack tx for updateValidatorSetV2", "error", err)
return nil, nil, nil, err
return err
}

// apply message
return p.applyTransaction(header.Coinbase, systemcontracts.ValidatorContract, u256.Num0, data, state, header, len(txs), systemTxs, usedGas, mining)
return p.applyTransaction(header.Coinbase, systemcontracts.ValidatorContract, u256.Num0, data, state, header, txs, receipts, systemTxs, usedGas, mining)
}

func (p *Parlia) getValidatorElectionInfo(header *types.Header, ibs *state.IntraBlockState) ([]ValidatorItem, error) {
Expand Down
Loading
Loading