Skip to content
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
3 changes: 0 additions & 3 deletions cluster/master/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ func (s *QKCMasterBackend) GetPeerInfolist() []rpc.PeerInfoForDisPlay {

func (s *QKCMasterBackend) AddTransaction(tx *types.Transaction) error {
evmTx := tx.EvmTx
if evmTx.GasPrice().Cmp(s.clusterConfig.Quarkchain.MinTXPoolGasPrice) < 0 {
return errors.New(fmt.Sprintf("invalid gasprice: tx min gas price is %d", s.clusterConfig.Quarkchain.MinTXPoolGasPrice.Uint64()))
}
fromShardSize, err := s.clusterConfig.Quarkchain.GetShardSizeByChainId(tx.EvmTx.FromChainID())
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cluster/master/master_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ func TestAddTransaction(t *testing.T) {
TxType: types.EvmTx,
}
err = master.AddTransaction(tx)
assert.Error(t, err)
assert.NoError(t, err)

evmTx = types.NewEvmTransaction(0, id1.GetRecipient(), new(big.Int), 0, new(big.Int).SetUint64(1000000000), 2, 2, 1, 0, []byte{}, 0, 0)
tx = &types.Transaction{
Expand Down
3 changes: 2 additions & 1 deletion cluster/shard/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,8 @@ func (s *ShardBackend) CreateBlockToMine(addr *account.Address) (types.IBlock, *
return nil, nil, 0, err
}
balance := balances.GetTokenBalance(s.MinorBlockChain.GetGenesisToken())
adjustedDifficulty, err := s.posw.PoSWDiffAdjust(header, balance)
stakePreBlock := s.MinorBlockChain.DecayByHeight(minorBlock.NumberU64())
adjustedDifficulty, err := s.posw.PoSWDiffAdjust(header, balance, stakePreBlock)
if err != nil {
log.Error("PoSW", "failed to compute PoSW difficulty", err)
return nil, nil, 0, err
Expand Down
9 changes: 8 additions & 1 deletion cmd/cluster/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,19 @@ func makeConfigNode(ctx *cli.Context) (*service.Node, qkcConfig) {
vm.PrecompiledContractsByzantium[v].SetEnableTime(cfg.Cluster.Quarkchain.EnableEvmTimeStamp)
}
}
if cfg.Cluster.Quarkchain.EnableNonReservedNativeTokenTimestamp == 0 && cfg.Cluster.Quarkchain.NetworkID == 1 {
cfg.Cluster.Quarkchain.EnableNonReservedNativeTokenTimestamp = params.MAINNET_ENABLE_NON_RESERVED_NATIVE_TOKEN_CONTRACT_TIMESTAMP
}
vm.SystemContracts[vm.NON_RESERVED_NATIVE_TOKEN].SetTimestamp(cfg.Cluster.Quarkchain.EnableNonReservedNativeTokenTimestamp)
for _, v := range params.PrecompiledContractsMnt {
if vm.PrecompiledContractsByzantium[v] != nil {
vm.PrecompiledContractsByzantium[v].SetEnableTime(cfg.Cluster.Quarkchain.EnableNonReservedNativeTokenTimestamp)
}
}
vm.SystemContracts[vm.NON_RESERVED_NATIVE_TOKEN].SetTimestamp(cfg.Cluster.Quarkchain.EnableNonReservedNativeTokenTimestamp)

if cfg.Cluster.Quarkchain.EnableGeneralNativeTokenTimestamp == 0 && cfg.Cluster.Quarkchain.NetworkID == 1 {
cfg.Cluster.Quarkchain.EnableGeneralNativeTokenTimestamp = params.MAINNET_ENABLE_GENERAL_NATIVE_TOKEN_CONTRACT_TIMESTAMP
}
vm.SystemContracts[vm.GENERAL_NATIVE_TOKEN].SetTimestamp(cfg.Cluster.Quarkchain.EnableGeneralNativeTokenTimestamp)

return stack, cfg
Expand Down
14 changes: 13 additions & 1 deletion common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/binary"
"encoding/gob"
"math"
"math/big"
"math/bits"
"net"
Expand All @@ -22,9 +23,20 @@ const (
)

var (
EmptyHash = ethCommon.Hash{}
EmptyHash = ethCommon.Hash{}
uint128Max = GetUint128Max()
)

func GetUint128Max() *big.Int {
pow2_64 := new(big.Int).Add(new(big.Int).SetUint64(math.MaxUint64), ethCommon.Big1)
pow2_128 := new(big.Int).Mul(pow2_64, pow2_64)
return new(big.Int).Sub(pow2_128, ethCommon.Big1)
}

func BiggerThanUint128Max(data *big.Int) bool {
return data.Cmp(uint128Max) > 0
}

/*
0b101, 0b11 -> True
0b101, 0b10 -> False
Expand Down
4 changes: 2 additions & 2 deletions consensus/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ type PoW interface {

type PoSWCalculator interface {
BuildSenderDisallowMap(headerHash common.Hash, recipient *account.Recipient) (map[account.Recipient]*big.Int, error)
PoSWDiffAdjust(header types.IHeader, balance *big.Int) (*big.Int, error)
PoSWDiffAdjust(header types.IHeader, balance *big.Int, stakePreBlock big.Int) (*big.Int, error)
IsPoSWEnabled(time uint64, height uint64) bool
GetPoSWInfo(header types.IHeader, stakes *big.Int, address account.Recipient) (*big.Int, uint64, uint64, error)
GetPoSWInfo(header types.IHeader, stakes *big.Int, address account.Recipient, stakePreBlock big.Int) (*big.Int, uint64, uint64, error)
}
9 changes: 5 additions & 4 deletions consensus/posw/posw.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ func NewPoSW(headReader headReader, config *config.POSWConfig) *PoSW {
}

/*PoSWDiffAdjust PoSW diff calc,already locked by insertChain*/
func (p *PoSW) PoSWDiffAdjust(header types.IHeader, stakes *big.Int) (*big.Int, error) {
func (p *PoSW) PoSWDiffAdjust(header types.IHeader, stakes *big.Int, stakePerBlock big.Int) (*big.Int, error) {
diff := header.GetDifficulty()
if stakes == nil {
return diff, nil
}
// Evaluate stakes before the to-be-added block
blockThreshold := new(big.Int).Div(stakes, p.config.TotalStakePerBlock).Uint64()

blockThreshold := new(big.Int).Div(stakes, &stakePerBlock).Uint64()
if blockThreshold == uint64(0) {
return diff, nil
}
Expand Down Expand Up @@ -155,15 +156,15 @@ func (p *PoSW) getCoinbaseAddressUntilBlock(headerHash common.Hash) ([]account.R
return addrs, nil
}

func (p *PoSW) GetPoSWInfo(header types.IHeader, stakes *big.Int, address account.Recipient) (effectiveDiff *big.Int, mineable, mined uint64, err error) {
func (p *PoSW) GetPoSWInfo(header types.IHeader, stakes *big.Int, address account.Recipient, stakePreBlock big.Int) (effectiveDiff *big.Int, mineable, mined uint64, err error) {
blockCnt, err := p.countCoinbaseBlockUntil(header.Hash(), address)
if err != nil {
return header.GetDifficulty(), 0, 0, err
}
if !p.IsPoSWEnabled(header.GetTime(), header.NumberU64()) || stakes == nil {
return header.GetDifficulty(), 0, blockCnt, nil
}
blockThreshold := new(big.Int).Div(stakes, p.config.TotalStakePerBlock).Uint64()
blockThreshold := new(big.Int).Div(stakes, &stakePreBlock).Uint64()
if blockThreshold > p.config.WindowSize {
blockThreshold = p.config.WindowSize
}
Expand Down
4 changes: 2 additions & 2 deletions consensus/posw/posw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ func appendNewBlock(blockchain *core.MinorBlockChain, acc1 account.Address, t *t
if balance, err := blockchain.GetBalance(newBlock.Coinbase().Recipient, nil); err != nil {
t.Fatalf("failed to get balance: %v", err)
} else {

adjustedDiff, err := core.GetPoSW(blockchain).PoSWDiffAdjust(newBlock.Header(), balance.GetTokenBalance(testGenesisTokenID))
stakePreBlock := blockchain.DecayByHeight(newBlock.NumberU64())
adjustedDiff, err := core.GetPoSW(blockchain).PoSWDiffAdjust(newBlock.Header(), balance.GetTokenBalance(testGenesisTokenID), stakePreBlock)
if err != nil {
t.Fatalf("failed to adjust posw diff: %v", err)
}
Expand Down
12 changes: 9 additions & 3 deletions core/minorblockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ type gasPriceSuggestionOracle struct {
Percentile uint64
}

type CoinbaseAmountAboutHeight struct {
CoinbaseAmount *types.TokenBalances
StakePreBlock big.Int
}

// MinorBlockChain represents the canonical chain given a database with a genesis
// block. The Blockchain manages chain imports, reverts, chain reorganisations.
//
Expand Down Expand Up @@ -113,7 +118,7 @@ type MinorBlockChain struct {
crossShardTxListCache *lru.Cache
rootBlockCache *lru.Cache
lastConfirmCache *lru.Cache
coinbaseAmountCache map[uint64]*types.TokenBalances
coinbaseAmountCache map[uint64]CoinbaseAmountAboutHeight

quit chan struct{} // blockchain quit channel
running int32 // running must be called atomically
Expand Down Expand Up @@ -193,7 +198,7 @@ func NewMinorBlockChain(
crossShardTxListCache: crossShardCache,
rootBlockCache: rootBlockCache,
lastConfirmCache: lastConfimCache,
coinbaseAmountCache: make(map[uint64]*types.TokenBalances),
coinbaseAmountCache: make(map[uint64]CoinbaseAmountAboutHeight),
engine: engine,
vmConfig: vmConfig,
heightToMinorBlockHashes: make(map[uint64]map[common.Hash]struct{}),
Expand Down Expand Up @@ -423,7 +428,8 @@ func (m *MinorBlockChain) GetAdjustedDifficulty(header types.IHeader) (*big.Int,
log.Error(m.logInfo, "PoSW: failed to get coinbase balance", err)
return nil, 0, err
}
poswAdjusted, err := m.posw.PoSWDiffAdjust(header, balance.GetTokenBalance(m.clusterConfig.Quarkchain.GetDefaultChainTokenID()))
stakePreBlock := m.DecayByHeight(header.NumberU64())
poswAdjusted, err := m.posw.PoSWDiffAdjust(header, balance.GetTokenBalance(m.clusterConfig.Quarkchain.GetDefaultChainTokenID()), stakePreBlock)
if err != nil {
log.Error(m.logInfo, "PoSW: err", err)
return nil, 0, err
Expand Down
62 changes: 47 additions & 15 deletions core/minorblockchain_addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,44 @@ func powerBigInt(data *big.Int, p uint64) *big.Int {

func (m *MinorBlockChain) getCoinbaseAmount(height uint64) *types.TokenBalances {
epoch := height / m.shardConfig.EpochInterval
balances, ok := m.coinbaseAmountCache[epoch]
if !ok {
decayNumerator := powerBigInt(m.clusterConfig.Quarkchain.BlockRewardDecayFactor.Num(), epoch)
decayDenominator := powerBigInt(new(big.Rat).Set(m.clusterConfig.Quarkchain.BlockRewardDecayFactor).Denom(), epoch)
coinbaseAmount := qkcCommon.BigIntMulBigRat(m.shardConfig.CoinbaseAmount, m.clusterConfig.Quarkchain.LocalFeeRate)
coinbaseAmount = new(big.Int).Mul(coinbaseAmount, decayNumerator)
coinbaseAmount = new(big.Int).Div(coinbaseAmount, decayDenominator)
data := make(map[uint64]*big.Int)
data[m.clusterConfig.Quarkchain.GetDefaultChainTokenID()] = coinbaseAmount
balances = types.NewTokenBalancesWithMap(data)
m.coinbaseAmountCache[epoch] = balances
cache, ok := m.coinbaseAmountCache[epoch]
if ok {
return cache.CoinbaseAmount.Copy()
}
m.calcCoinbaseAmountByHeight(epoch)
cache, _ = m.coinbaseAmountCache[epoch]
return cache.CoinbaseAmount.Copy()
}

func (m *MinorBlockChain) DecayByHeight(height uint64) big.Int {
epoch := height / m.shardConfig.EpochInterval
cache, ok := m.coinbaseAmountCache[epoch]
if ok {
return cache.StakePreBlock
}
m.calcCoinbaseAmountByHeight(epoch)
cache, _ = m.coinbaseAmountCache[epoch]
return cache.StakePreBlock
}

func (m *MinorBlockChain) calcCoinbaseAmountByHeight(epoch uint64) {
decayNumerator := powerBigInt(m.clusterConfig.Quarkchain.BlockRewardDecayFactor.Num(), epoch)
decayDenominator := powerBigInt(new(big.Rat).Set(m.clusterConfig.Quarkchain.BlockRewardDecayFactor).Denom(), epoch)
coinbaseAmount := qkcCommon.BigIntMulBigRat(m.shardConfig.CoinbaseAmount, m.clusterConfig.Quarkchain.LocalFeeRate)
coinbaseAmount = new(big.Int).Mul(coinbaseAmount, decayNumerator)
coinbaseAmount = new(big.Int).Div(coinbaseAmount, decayDenominator)
data := make(map[uint64]*big.Int)
data[m.clusterConfig.Quarkchain.GetDefaultChainTokenID()] = coinbaseAmount
balances := types.NewTokenBalancesWithMap(data)

value := m.clusterConfig.Quarkchain.GetShardConfigByFullShardID(m.branch.Value).PoswConfig.TotalStakePerBlock
delayData := new(big.Int).Mul(value, decayNumerator)
delayData = new(big.Int).Div(delayData, decayDenominator)

m.coinbaseAmountCache[epoch] = CoinbaseAmountAboutHeight{
CoinbaseAmount: balances,
StakePreBlock: *delayData,
}
return balances.Copy()
}

func (m *MinorBlockChain) putMinorBlock(mBlock *types.MinorBlock, xShardReceiveTxList []*types.CrossShardTransactionDeposit) error {
Expand Down Expand Up @@ -783,7 +808,12 @@ func (m *MinorBlockChain) checkTxBeforeApply(stateT *state.StateDB, tx *types.Tr
if tx.EvmTx.Gas() > diff.Uint64() {
return ErrorTxContinue
}
if tx.EvmTx.GasPrice().Cmp(m.clusterConfig.Quarkchain.MinMiningGasPrice) < 0 {

defaultGasPrice, err := ConvertToDefaultChainTokenGasPrice(stateT, m.ChainConfig(), tx.EvmTx.GasTokenID(), tx.EvmTx.GasPrice())
if err != nil {
return ErrorTxContinue
}
if defaultGasPrice.Cmp(m.clusterConfig.Quarkchain.MinMiningGasPrice) < 0 {
return ErrorTxContinue
}
if header.Time < m.clusterConfig.Quarkchain.EnableEvmTimeStamp {
Expand Down Expand Up @@ -1725,7 +1755,8 @@ func (m *MinorBlockChain) PoswInfo(mBlock *types.MinorBlock) (*rpc.PoSWInfo, err
return nil, err
}
stakes := evmState.GetBalance(header.Coinbase.Recipient, m.clusterConfig.Quarkchain.GetDefaultChainTokenID())
diff, minable, mined, _ := m.posw.GetPoSWInfo(header, stakes, header.Coinbase.Recipient)
stakePreBlock := m.DecayByHeight(mBlock.NumberU64())
diff, minable, mined, _ := m.posw.GetPoSWInfo(header, stakes, header.Coinbase.Recipient, stakePreBlock)
return &rpc.PoSWInfo{
EffectiveDifficulty: diff,
PoswMineableBlocks: minable,
Expand All @@ -1749,7 +1780,8 @@ func (m *MinorBlockChain) CommitMinorBlockByHash(h common.Hash) {
}

func (m *MinorBlockChain) GetMiningInfo(address account.Recipient, stake *types.TokenBalances) (mineable, mined uint64, err error) {
_, mineable, mined, err = m.posw.GetPoSWInfo(m.CurrentBlock().Header(), stake.GetTokenBalance(m.Config().GetDefaultChainTokenID()), address)
stakePreBlock := m.DecayByHeight(m.CurrentBlock().NumberU64())
_, mineable, mined, err = m.posw.GetPoSWInfo(m.CurrentBlock().Header(), stake.GetTokenBalance(m.Config().GetDefaultChainTokenID()), address, stakePreBlock)
return
}

Expand Down
13 changes: 10 additions & 3 deletions core/native_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package core

import (
"bou.ke/monkey"
"github.com/QuarkChain/goquarkchain/params"
ethParams "github.com/ethereum/go-ethereum/params"
"io/ioutil"
"math/big"
"os"
"testing"

"bou.ke/monkey"
"github.com/QuarkChain/goquarkchain/params"
ethParams "github.com/ethereum/go-ethereum/params"

"github.com/QuarkChain/goquarkchain/account"
"github.com/QuarkChain/goquarkchain/common"
"github.com/QuarkChain/goquarkchain/core/types"
Expand Down Expand Up @@ -122,6 +123,9 @@ func TestNativeTokenGas(t *testing.T) {
monkey.Patch(PayNativeTokenAsGas, func(a vm.StateDB, b *ethParams.ChainConfig, c uint64, d uint64, gasPrice *big.Int) (uint8, *big.Int, error) {
return 100, gasPrice, nil
})
monkey.Patch(GetGasUtilityInfo, func(a vm.StateDB, b *ethParams.ChainConfig, c uint64, gasPrice *big.Int) (uint8, *big.Int, error) {
return 100, gasPrice, nil
})
defer monkey.UnpatchAll()
dirname, err := ioutil.TempDir(os.TempDir(), "qkcdb_test_")
if err != nil {
Expand Down Expand Up @@ -297,6 +301,9 @@ func TestXshardNativeTokenGasSent(t *testing.T) {
monkey.Patch(PayNativeTokenAsGas, func(a vm.StateDB, b *ethParams.ChainConfig, c uint64, d uint64, gasPrice *big.Int) (uint8, *big.Int, error) {
return 100, gasPrice, nil
})
monkey.Patch(GetGasUtilityInfo, func(a vm.StateDB, b *ethParams.ChainConfig, c uint64, gasPrice *big.Int) (uint8, *big.Int, error) {
return 100, gasPrice, nil
})
defer monkey.UnpatchAll()
qeth := common.TokenIDEncode("QETHXX")
qkc := common.TokenIDEncode("QKC")
Expand Down
6 changes: 3 additions & 3 deletions core/rootblockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,7 @@ func (bc *RootBlockChain) GetAdjustedDifficultyToMine(header types.IHeader) (*bi
if err != nil {
log.Debug("get PoSW stakes", "err", err, "coinbase", header.GetCoinbase().ToHex())
}
poswAdjusted, err := bc.posw.PoSWDiffAdjust(header, stakes)
poswAdjusted, err := bc.posw.PoSWDiffAdjust(header, stakes, *bc.chainConfig.Root.PoSWConfig.TotalStakePerBlock)
if err != nil {
log.Debug("PoSW diff adjust", "err", err, "coinbase", header.GetCoinbase().ToHex())
}
Expand Down Expand Up @@ -1120,7 +1120,7 @@ func (bc *RootBlockChain) getPoSWAdjustedDiff(header types.IHeader) (*big.Int, e
if err != nil {
return nil, err
}
return bc.posw.PoSWDiffAdjust(header, stakes)
return bc.posw.PoSWDiffAdjust(header, stakes, *bc.chainConfig.Root.PoSWConfig.TotalStakePerBlock)
}

func (bc *RootBlockChain) getSignedPoSWStakes(header types.IHeader) (*big.Int, error) {
Expand Down Expand Up @@ -1424,7 +1424,7 @@ func (bc *RootBlockChain) PoSWInfo(header *types.RootBlockHeader) (*rpc.PoSWInfo
return nil, nil
}
stakes, _ := bc.getSignedPoSWStakes(header)
diff, mineable, mined, _ := bc.posw.GetPoSWInfo(header, stakes, header.Coinbase.Recipient)
diff, mineable, mined, _ := bc.posw.GetPoSWInfo(header, stakes, header.Coinbase.Recipient, *bc.chainConfig.Root.PoSWConfig.TotalStakePerBlock)
return &rpc.PoSWInfo{
EffectiveDifficulty: diff,
PoswMinedBlocks: mined + 1,
Expand Down
8 changes: 8 additions & 0 deletions core/shardstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ func TestGasPrice(t *testing.T) {
monkey.Patch(PayNativeTokenAsGas, func(a vm.StateDB, b *ethParams.ChainConfig, c uint64, d uint64, gasPrice *big.Int) (uint8, *big.Int, error) {
return 100, gasPrice, nil
})
monkey.Patch(GetGasUtilityInfo, func(a vm.StateDB, b *ethParams.ChainConfig, c uint64, gasPrice *big.Int) (uint8, *big.Int, error) {
return 100, gasPrice, nil
})
defer monkey.UnpatchAll()
addContractAddrBalance = true
defer func() {
Expand Down Expand Up @@ -3024,6 +3027,11 @@ func TestPayNativeTokenAsGasContractAPI(t *testing.T) {
refundPercentage, gasPrice, err = GetGasUtilityInfo(evmState, shardState.ethChainConfig, tokenID, gasPriceInNativeToken)
assert.Equal(t, uint8(60), refundPercentage)
assert.Equal(t, big.NewInt(2), gasPrice)

data, err := ConvertToDefaultChainTokenGasPrice(evmState, shardState.ethChainConfig, tokenID, new(big.Int).SetInt64(60000))
assert.NoError(t, err)
assert.Equal(t, data.Uint64(), uint64(2))

//# exchange the Qkc with the native token
refundPercentage, gasPrice, err = PayNativeTokenAsGas(evmState, shardState.ethChainConfig, tokenID, 3, gasPriceInNativeToken)
assert.Equal(t, uint8(60), refundPercentage)
Expand Down
19 changes: 19 additions & 0 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ func ValidateTransaction(state vm.StateDB, chainConfig *params.ChainConfig, tx *
from = &fromAddress.Recipient
}

// not need to check gas(uint64)
if qkcCmn.BiggerThanUint128Max(tx.EvmTx.GasPrice()) || tx.EvmTx.GasTokenID() > qkcCmn.TOKENIDMAX ||
tx.EvmTx.TransferTokenID() > qkcCmn.TOKENIDMAX {
return fmt.Errorf("startgas, gasprice, and token_id must <= UINT128_MAX")
}
reqNonce := state.GetNonce(*from)
if bytes.Equal(from.Bytes(), account.Recipient{}.Bytes()) {
reqNonce = 0
Expand Down Expand Up @@ -317,6 +322,10 @@ func ApplyCrossShardDeposit(config *params.ChainConfig, bc ChainContext, header

func PayNativeTokenAsGas(evmState vm.StateDB, config *params.ChainConfig, tokenID, gas uint64,
gasPriceInNativeToken *big.Int) (uint8, *big.Int, error) {
// not need to check gas(uint64)
if tokenID > qkcCmn.TOKENIDMAX || qkcCmn.BiggerThanUint128Max(gasPriceInNativeToken) {
return 0, nil, fmt.Errorf("PayNativeTokenAsGas : tokenid %v > TOKENIDMAX %v gasPriceInNativeToken %v > Uint128Max ", tokenID, qkcCmn.TOKENIDMAX, gasPriceInNativeToken)
}

//# Call the `payAsGas` function
data := common.Hex2Bytes("5ae8f7f1")
Expand Down Expand Up @@ -359,3 +368,13 @@ func callGeneralNativeTokenManager(evmState vm.StateDB, config *params.ChainConf
convertedGasPrice := new(big.Int).SetBytes(ret[32:64])
return uint8(refundRate), convertedGasPrice, nil
}

func ConvertToDefaultChainTokenGasPrice(state vm.StateDB, paramConfig *params.ChainConfig, tokenID uint64, gasprice *big.Int) (*big.Int, error) {
if tokenID == state.GetQuarkChainConfig().GetDefaultChainTokenID() {
return gasprice, nil
}
snapshot := state.Snapshot()
_, data, err := GetGasUtilityInfo(state, paramConfig, tokenID, gasprice)
state.RevertToSnapshot(snapshot)
return data, err
}
Loading