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

Fix eth_estimateGas params and Galaxias TxGas for testnet #226

Merged
merged 1 commit into from
Mar 18, 2022
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
16 changes: 9 additions & 7 deletions internal/kaiapi/transaction_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,17 @@ func (args *TransactionArgs) UnmarshalJSON(data []byte) error {
fromAddress := common.HexToAddress(fromAddressStr)
args.From = &fromAddress

inputStr, ok := params["input"].(string)
if !ok {
inputStr, ok = params["data"].(string)
if params["input"] != nil || params["data"] != nil {
inputStr, ok := params["input"].(string)
if !ok {
return &parseError{param: "input (data)"}
inputStr, ok = params["data"].(string)
if !ok {
return &parseError{param: "input (data)"}
}
inputField := (common.Bytes)(common.FromHex(inputStr))
args.Input = &inputField
args.Data = &inputField
}
inputField := (common.Bytes)(common.FromHex(inputStr))
args.Input = &inputField
args.Data = &inputField
}

if gas, ok := params["gas"].(float64); ok {
Expand Down
4 changes: 3 additions & 1 deletion mainchain/api_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ type APIBackend interface {

func (k *KardiaService) HeaderByHeight(ctx context.Context, height rpc.BlockHeight) *types.Header {
// Return the latest block if rpc.LatestBlockHeight or rpc.PendingBlockHeight has been passed in
if height.Uint64() >= rpc.PendingBlockHeight.Uint64() {
if height.Uint64() == rpc.PendingBlockHeight.Uint64() {
return k.blockchain.CurrentBlock().Header()
} else if height.Uint64() == rpc.LatestBlockHeight.Uint64() {
return k.blockchain.GetHeaderByHeight(k.blockchain.CurrentBlock().Header().Height - 1)
}
return k.blockchain.GetHeaderByHeight(height.Uint64())
}
Expand Down
2 changes: 1 addition & 1 deletion mainchain/blockchain/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func ApplyTransaction(config *configs.ChainConfig, logger log.Logger, bc vm.Chai
txContext := NewKVMTxContext(msg)
// Create a new environment which holds all relevant information
// about the transaction and calling mechanisms.
vmenv := kvm.NewKVM(context, txContext, statedb, configs.MainnetChainConfig, cfg)
vmenv := kvm.NewKVM(context, txContext, statedb, bc.Config(), cfg)
vmenv.Reset(txContext, statedb)
// Apply the transaction to the current state (included in the env)
result, err := ApplyMessage(vmenv, msg, gp)
Expand Down
4 changes: 3 additions & 1 deletion mainchain/tracers/js/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,9 @@ func (jst *jsTracer) CaptureStart(env *kvm.KVM, from common.Address, to common.A
jst.activePrecompiles = kvm.ActivePrecompiles()

// Compute intrinsic gas
intrinsicGas, err := tx_pool.IntrinsicGas(input, jst.ctx["type"] == "CREATE", false)
height := env.BlockContext.BlockHeight.Uint64()
isGalaxias := env.ChainConfig().IsGalaxias(&height)
intrinsicGas, err := tx_pool.IntrinsicGas(input, jst.ctx["type"] == "CREATE", !isGalaxias)
if err != nil {
return
}
Expand Down
8 changes: 7 additions & 1 deletion mainchain/tx_pool/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ type TxPool struct {
signer types.Signer
mu sync.RWMutex

isGalaxias bool // Fork indicator whether we are in the Galaxias stage.

currentState *state.StateDB // Current state in the blockchain head
pendingNonces *txNoncer // Pending state tracking virtual nonces
currentMaxGas uint64 // Current gas limit for transaction caps
Expand Down Expand Up @@ -584,7 +586,7 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
return ErrInsufficientFunds
}
// Ensure the transaction has more gas than the basic tx fee.
intrGas, err := IntrinsicGas(tx.Data(), tx.To() == nil, false)
intrGas, err := IntrinsicGas(tx.Data(), tx.To() == nil, !pool.isGalaxias)
if err != nil {
return err
}
Expand Down Expand Up @@ -1246,6 +1248,10 @@ func (pool *TxPool) reset(oldHead, newHead *types.Header) {
log.Debug("Reinjecting stale transactions", "count", len(reinject))
senderCacher.recover(pool.signer, reinject)
pool.addTxsLocked(reinject, false)

// Update all fork indicator by next pending block number.
next := newHead.Height + 1
pool.isGalaxias = pool.chainCfg.IsGalaxias(&next)
}

// promoteExecutables moves transactions that have become processable from the
Expand Down