Skip to content

Commit

Permalink
support trace system tx (#534)
Browse files Browse the repository at this point in the history
  • Loading branch information
blxdyx authored Oct 17, 2024
1 parent 671833a commit d11bc94
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
26 changes: 2 additions & 24 deletions consensus/parlia/parlia.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,6 @@ var (
// 100 native token
maxSystemBalance = new(uint256.Int).Mul(uint256.NewInt(100), uint256.NewInt(params.Ether))

systemContracts = map[libcommon.Address]struct{}{
systemcontracts.ValidatorContract: {},
systemcontracts.SlashContract: {},
systemcontracts.SystemRewardContract: {},
systemcontracts.LightClientContract: {},
systemcontracts.RelayerHubContract: {},
systemcontracts.GovHubContract: {},
systemcontracts.TokenHubContract: {},
systemcontracts.RelayerIncentivizeContract: {},
systemcontracts.CrossChainContract: {},
systemcontracts.StakeHubContract: {},
systemcontracts.GovernorContract: {},
systemcontracts.GovTokenContract: {},
systemcontracts.TimelockContract: {},
systemcontracts.TokenRecoverPortalContract: {},
}

validatorItemsCache []ValidatorItem
maxElectedValidatorsCache = big.NewInt(0)
)
Expand Down Expand Up @@ -1273,22 +1256,17 @@ func (p *Parlia) IsSystemTransaction(tx types.Transaction, header *types.Header)
if err != nil {
return false, errors.New("UnAuthorized transaction")
}
if sender == header.Coinbase && isToSystemContract(*tx.GetTo()) && tx.GetPrice().IsZero() {
if sender == header.Coinbase && core.IsToSystemContract(*tx.GetTo()) && tx.GetPrice().IsZero() {
return true, nil
}
return false, nil
}

func isToSystemContract(to libcommon.Address) bool {
_, ok := systemContracts[to]
return ok
}

func (p *Parlia) IsSystemContract(to *libcommon.Address) bool {
if to == nil {
return false
}
return isToSystemContract(*to)
return core.IsToSystemContract(*to)
}

func (p *Parlia) EnoughDistance(chain consensus.ChainReader, header *types.Header) bool {
Expand Down
22 changes: 22 additions & 0 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,3 +546,25 @@ func BlockPostValidation(gasUsed, blobGasUsed uint64, checkReceipts bool, receip
}
return nil
}

var systemContracts = map[libcommon.Address]struct{}{
systemcontracts.ValidatorContract: {},
systemcontracts.SlashContract: {},
systemcontracts.SystemRewardContract: {},
systemcontracts.LightClientContract: {},
systemcontracts.RelayerHubContract: {},
systemcontracts.GovHubContract: {},
systemcontracts.TokenHubContract: {},
systemcontracts.RelayerIncentivizeContract: {},
systemcontracts.CrossChainContract: {},
systemcontracts.StakeHubContract: {},
systemcontracts.GovernorContract: {},
systemcontracts.GovTokenContract: {},
systemcontracts.TimelockContract: {},
systemcontracts.TokenRecoverPortalContract: {},
}

func IsToSystemContract(to libcommon.Address) bool {
_, ok := systemContracts[to]
return ok
}
4 changes: 2 additions & 2 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,9 @@ func (st *StateTransition) TransitionDb(refunds bool, gasBailout bool) (*evmtype
// BSC always gave gas bailout due to system transactions that set 2^256/2 gas limit and
// So when trace systemTx, skip PreCheck
var skipCheck bool
if st.isParlia && st.msg.Gas() == math.MaxUint64/2 && st.gasPrice.IsZero() {
if st.isParlia && st.msg.Gas() == math.MaxUint64/2 && IsToSystemContract(*st.msg.To()) && st.msg.From() == coinbase {
skipCheck = true
st.state.AddBalance(coinbase, st.state.GetBalance(consensus.SystemAddress), tracing.BalanceChangeUnspecified)
st.state.AddBalance(coinbase, st.msg.Value(), tracing.BalanceChangeUnspecified)
}

// Check clauses 1-3 and 6, buy gas if everything is correct
Expand Down

0 comments on commit d11bc94

Please sign in to comment.