Skip to content

Commit 47fa42a

Browse files
committed
Updated the struct Message to align with Ethereum code.
1 parent e4ce1ac commit 47fa42a

File tree

4 files changed

+86
-47
lines changed

4 files changed

+86
-47
lines changed

core/state_transition.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ type Message interface {
8989
Value() *big.Int
9090

9191
Nonce() uint64
92-
CheckNonce() bool
92+
SkipNonceChecks() bool
9393
Data() []byte
9494
Type() types.TransactionType
9595
BlockNum() *big.Int
@@ -195,7 +195,7 @@ func (st *StateTransition) buyGas() error {
195195

196196
func (st *StateTransition) preCheck() error {
197197
// Make sure this transaction's nonce is correct.
198-
if st.msg.CheckNonce() {
198+
if !st.msg.SkipNonceChecks() {
199199
nonce := st.state.GetNonce(st.msg.From())
200200

201201
if nonce < st.msg.Nonce() {

core/types/eth_transaction.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -358,13 +358,13 @@ func (tx *EthTransaction) IsEthCompatible() bool {
358358
// XXX Rename message to something less arbitrary?
359359
func (tx *EthTransaction) AsMessage(s Signer) (Message, error) {
360360
msg := Message{
361-
nonce: tx.data.AccountNonce,
362-
gasLimit: tx.data.GasLimit,
363-
gasPrice: new(big.Int).Set(tx.data.Price),
364-
to: tx.data.Recipient,
365-
amount: tx.data.Amount,
366-
data: tx.data.Payload,
367-
checkNonce: true,
361+
nonce: tx.data.AccountNonce,
362+
gasLimit: tx.data.GasLimit,
363+
gasPrice: new(big.Int).Set(tx.data.Price),
364+
to: tx.data.Recipient,
365+
value: tx.data.Amount,
366+
data: tx.data.Payload,
367+
skipNonceChecks: false,
368368
}
369369

370370
var err error

core/types/transaction.go

+76-37
Original file line numberDiff line numberDiff line change
@@ -474,13 +474,13 @@ func (tx *Transaction) ConvertToEth() *EthTransaction {
474474
// XXX Rename message to something less arbitrary?
475475
func (tx *Transaction) AsMessage(s Signer) (Message, error) {
476476
msg := Message{
477-
nonce: tx.data.AccountNonce,
478-
gasLimit: tx.data.GasLimit,
479-
gasPrice: new(big.Int).Set(tx.data.Price),
480-
to: tx.data.Recipient,
481-
amount: tx.data.Amount,
482-
data: tx.data.Payload,
483-
checkNonce: true,
477+
nonce: tx.data.AccountNonce,
478+
gasLimit: tx.data.GasLimit,
479+
gasPrice: new(big.Int).Set(tx.data.Price),
480+
to: tx.data.Recipient,
481+
value: tx.data.Amount,
482+
data: tx.data.Payload,
483+
skipNonceChecks: false,
484484
}
485485

486486
var err error
@@ -681,43 +681,82 @@ func (t *TransactionsByPriceAndNonce) Pop() {
681681
// Message is a fully derived transaction and implements core.Message
682682
// NOTE: In a future PR this will be removed.
683683
type Message struct {
684-
to *common.Address
685-
from common.Address
686-
nonce uint64
687-
amount *big.Int
688-
gasLimit uint64
689-
gasPrice *big.Int
690-
data []byte
691-
checkNonce bool
692-
blockNum *big.Int
693-
txType TransactionType
694-
}
684+
to *common.Address
685+
from common.Address
686+
nonce uint64
687+
value *big.Int
688+
gasLimit uint64
689+
gasPrice *big.Int
690+
gasFeeCap *big.Int
691+
gasTipCap *big.Int
692+
data []byte
693+
// AccessList types.AccessList TODO: implemented in Berlin 2021-04-15
694+
BlobGasFeeCap *big.Int
695+
BlobHashes []common.Hash
696+
697+
// SetCodeAuthorizations []types.SetCodeAuthorization TODO: understand do we need this
698+
699+
// When SkipNonceChecks is true, the message nonce is not checked against the
700+
// account nonce in state.
701+
// This field will be set to true for operations like RPC eth_call.
702+
skipNonceChecks bool
703+
704+
// When SkipFromEOACheck is true, the message sender is not checked to be an EOA.
705+
skipFromEOACheck bool
706+
707+
blockNum *big.Int
708+
txType TransactionType
709+
}
710+
711+
//type Message struct {
712+
// To *common.Address
713+
// From common.Address
714+
// Nonce uint64
715+
// Value *big.Int
716+
// GasLimit uint64
717+
// GasPrice *big.Int
718+
// GasFeeCap *big.Int
719+
// GasTipCap *big.Int
720+
// Data []byte
721+
// AccessList types.AccessList
722+
// BlobGasFeeCap *big.Int
723+
// BlobHashes []common.Hash
724+
// SetCodeAuthorizations []types.SetCodeAuthorization
725+
//
726+
// // When SkipNonceChecks is true, the message nonce is not checked against the
727+
// // account nonce in state.
728+
// // This field will be set to true for operations like RPC eth_call.
729+
// SkipNonceChecks bool
730+
//
731+
// // When SkipFromEOACheck is true, the message sender is not checked to be an EOA.
732+
// SkipFromEOACheck bool
733+
//}
695734

696735
// NewMessage returns new message.
697-
func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, checkNonce bool) Message {
736+
func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, skipNonceChecks bool) Message {
698737
return Message{
699-
from: from,
700-
to: to,
701-
nonce: nonce,
702-
amount: amount,
703-
gasLimit: gasLimit,
704-
gasPrice: gasPrice,
705-
data: data,
706-
checkNonce: checkNonce,
738+
from: from,
739+
to: to,
740+
nonce: nonce,
741+
value: amount,
742+
gasLimit: gasLimit,
743+
gasPrice: gasPrice,
744+
data: data,
745+
skipNonceChecks: skipNonceChecks,
707746
}
708747
}
709748

710749
// NewStakingMessage returns new message of staking type
711750
// always need checkNonce
712751
func NewStakingMessage(from common.Address, nonce uint64, gasLimit uint64, gasPrice *big.Int, data []byte, blockNum *big.Int) Message {
713752
return Message{
714-
from: from,
715-
nonce: nonce,
716-
gasLimit: gasLimit,
717-
gasPrice: new(big.Int).Set(gasPrice),
718-
data: data,
719-
checkNonce: true,
720-
blockNum: blockNum,
753+
from: from,
754+
nonce: nonce,
755+
gasLimit: gasLimit,
756+
gasPrice: new(big.Int).Set(gasPrice),
757+
data: data,
758+
skipNonceChecks: false,
759+
blockNum: blockNum,
721760
}
722761
}
723762

@@ -738,7 +777,7 @@ func (m Message) GasPrice() *big.Int {
738777

739778
// Value returns the value amount from Message.
740779
func (m Message) Value() *big.Int {
741-
return m.amount
780+
return m.value
742781
}
743782

744783
// Gas returns gas limit of the Message.
@@ -757,8 +796,8 @@ func (m Message) Data() []byte {
757796
}
758797

759798
// CheckNonce returns checkNonce of Message.
760-
func (m Message) CheckNonce() bool {
761-
return m.checkNonce
799+
func (m Message) SkipNonceChecks() bool {
800+
return m.skipNonceChecks
762801
}
763802

764803
// Type returns the type of message

rpc/harmony/types.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (args *CallArgs) ToMessage(globalGasCap *big.Int) types.Message {
7272
data = []byte(*args.Data)
7373
}
7474

75-
msg := types.NewMessage(addr, args.To, 0, value, gas, gasPrice, data, false)
75+
msg := types.NewMessage(addr, args.To, 0, value, gas, gasPrice, data, true)
7676
return msg
7777
}
7878

0 commit comments

Comments
 (0)