Skip to content

Commit

Permalink
Effective gas price to staking transaction.
Browse files Browse the repository at this point in the history
  • Loading branch information
Frozen committed Jan 9, 2025
1 parent d97d413 commit d308ae9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ func ApplyStakingTransaction(
receipt = types.NewReceipt(root, false, *usedGas)
receipt.TxHash = tx.Hash()
receipt.GasUsed = gas
receipt.EffectiveGasPrice = tx.EffectiveGasPrice(big.NewInt(0), nil)

if config.IsReceiptLog(header.Epoch()) {
receipt.Logs = statedb.GetLogs(tx.Hash(), header.Number().Uint64(), header.Hash())
Expand Down
2 changes: 2 additions & 0 deletions rpc/harmony/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ type StakingTxReceipt struct {
Type hexutil.Uint64 `json:"type"`
Root hexutil.Bytes `json:"root"`
Status hexutil.Uint `json:"status"`
EffectiveGasPrice hexutil.Big `json:"effectiveGasPrice"`
}

// CxReceipt represents a CxReceipt that will serialize to the RPC representation of a CxReceipt
Expand Down Expand Up @@ -403,6 +404,7 @@ func NewStakingTxReceipt(
Type: hexutil.Uint64(tx.StakingType()),
Root: receipt.PostState,
Status: hexutil.Uint(receipt.Status),
EffectiveGasPrice: hexutil.Big(*receipt.EffectiveGasPrice),
}

// Set empty array for empty logs
Expand Down
2 changes: 2 additions & 0 deletions rpc/harmony/v2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ type StakingTxReceipt struct {
Type staking.Directive `json:"type"`
Root hexutil.Bytes `json:"root"`
Status uint `json:"status"`
EffectiveGasPrice hexutil.Big `json:"effectiveGasPrice"`
}

// CxReceipt represents a CxReceipt that will serialize to the RPC representation of a CxReceipt
Expand Down Expand Up @@ -439,6 +440,7 @@ func NewStakingTxReceipt(
Type: tx.StakingType(),
Root: receipt.PostState,
Status: uint(receipt.Status),
EffectiveGasPrice: hexutil.Big(*receipt.EffectiveGasPrice),
}

// Set empty array for empty logs
Expand Down
9 changes: 9 additions & 0 deletions staking/types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ func (d *txdata) CopyFrom(d2 *txdata) {
d.Hash = copyHash(d2.Hash)
}

func (d *txdata) effectiveGasPrice(dst *big.Int, baseFee *big.Int) *big.Int {
return dst.Set(d.Price)
}

func copyHash(hash *common.Hash) *common.Hash {
if hash == nil {
return nil
Expand Down Expand Up @@ -263,6 +267,11 @@ func (tx *StakingTransaction) IsEthCompatible() bool {
return false
}

// EffectiveGasPrice returns the effective gas price of the transaction.
func (tx *StakingTransaction) EffectiveGasPrice(dst *big.Int, baseFee *big.Int) *big.Int {
return tx.data.effectiveGasPrice(dst, baseFee)
}

type writeCounter common.StorageSize

func (c *writeCounter) Write(b []byte) (int, error) {
Expand Down

0 comments on commit d308ae9

Please sign in to comment.