eth: rpc: fix sendRawTransaction, transactionIndex, feeHistory (#9736)

* Eth JSON-RPC API: add transactionIndex

* Eth JSON-RPC API: fix EthFeeHistory and EthSendRawTransaction

* Eth JSON-RPC API: fix parsing block parameter for getBlockByNumber

* fix itest
This commit is contained in:
ychiao
2022-11-27 18:44:43 -08:00
committed by GitHub
parent 176275267b
commit f1493fbee7
8 changed files with 72 additions and 20 deletions
+1 -1
View File
@@ -67,7 +67,7 @@ func (e *EthModuleDummy) EthGetBalance(ctx context.Context, address api.EthAddre
return api.EthBigIntZero, ErrImplementMe
}
func (e *EthModuleDummy) EthFeeHistory(ctx context.Context, blkCount api.EthUint64, newestBlk string, rewardPercentiles []int64) (api.EthFeeHistory, error) {
func (e *EthModuleDummy) EthFeeHistory(ctx context.Context, blkCount api.EthUint64, newestBlk string, rewardPercentiles []float64) (api.EthFeeHistory, error) {
return api.EthFeeHistory{}, ErrImplementMe
}
+33 -5
View File
@@ -44,7 +44,7 @@ type EthModuleAPI interface {
EthGetCode(ctx context.Context, address api.EthAddress, blkOpt string) (api.EthBytes, error)
EthGetStorageAt(ctx context.Context, address api.EthAddress, position api.EthBytes, blkParam string) (api.EthBytes, error)
EthGetBalance(ctx context.Context, address api.EthAddress, blkParam string) (api.EthBigInt, error)
EthFeeHistory(ctx context.Context, blkCount api.EthUint64, newestBlk string, rewardPercentiles []int64) (api.EthFeeHistory, error)
EthFeeHistory(ctx context.Context, blkCount api.EthUint64, newestBlk string, rewardPercentiles []float64) (api.EthFeeHistory, error)
EthChainId(ctx context.Context) (api.EthUint64, error)
NetVersion(ctx context.Context) (string, error)
NetListening(ctx context.Context) (bool, error)
@@ -54,7 +54,6 @@ type EthModuleAPI interface {
EthCall(ctx context.Context, tx api.EthCall, blkParam string) (api.EthBytes, error)
EthMaxPriorityFeePerGas(ctx context.Context) (api.EthBigInt, error)
EthSendRawTransaction(ctx context.Context, rawTx api.EthBytes) (api.EthHash, error)
// EthFeeHistory(ctx context.Context, blkCount string)
}
var _ EthModuleAPI = *new(api.FullNode)
@@ -140,9 +139,15 @@ func (a *EthModule) EthGetBlockByHash(ctx context.Context, blkHash api.EthHash,
}
func (a *EthModule) EthGetBlockByNumber(ctx context.Context, blkNum string, fullTxInfo bool) (api.EthBlock, error) {
var num api.EthUint64
err := num.UnmarshalJSON([]byte(`"` + blkNum + `"`))
typ, num, err := api.ParseBlkNumOption(blkNum)
if err != nil {
return api.EthBlock{}, fmt.Errorf("cannot parse block number: %v", err)
}
switch typ {
case api.BlkNumLatest:
num = api.EthUint64(a.Chain.GetHeaviestTipSet().Height()) - 1
case api.BlkNumPending:
num = api.EthUint64(a.Chain.GetHeaviestTipSet().Height())
}
@@ -377,7 +382,7 @@ func (a *EthModule) EthChainId(ctx context.Context) (api.EthUint64, error) {
return api.EthUint64(build.Eip155ChainId), nil
}
func (a *EthModule) EthFeeHistory(ctx context.Context, blkCount api.EthUint64, newestBlkNum string, rewardPercentiles []int64) (api.EthFeeHistory, error) {
func (a *EthModule) EthFeeHistory(ctx context.Context, blkCount api.EthUint64, newestBlkNum string, rewardPercentiles []float64) (api.EthFeeHistory, error) {
if blkCount > 1024 {
return api.EthFeeHistory{}, fmt.Errorf("block count should be smaller than 1024")
}
@@ -497,6 +502,13 @@ func (a *EthModule) EthSendRawTransaction(ctx context.Context, rawTx api.EthByte
return api.EmptyEthHash, err
}
_, err = a.StateAPI.StateGetActor(ctx, smsg.Message.To, types.EmptyTSK)
if err != nil {
// if actor does not exist on chain yet, set the method to 0 because
// embryos only implement method 0
smsg.Message.Method = builtin.MethodSend
}
cid, err := a.MpoolAPI.MpoolPush(ctx, smsg)
if err != nil {
return api.EmptyEthHash, err
@@ -768,6 +780,21 @@ func (a *EthModule) newEthTxFromFilecoinMessageLookup(ctx context.Context, msgLo
return api.EthTx{}, err
}
// lookup the transactionIndex
txIdx := -1
msgs, err := a.Chain.MessagesForTipset(ctx, parentTs)
if err != nil {
return api.EthTx{}, err
}
for i, msg := range msgs {
if msg.Cid() == msgLookup.Message {
txIdx = i
}
}
if txIdx == -1 {
return api.EthTx{}, fmt.Errorf("cannot find the msg in the tipset")
}
blkHash, err := api.NewEthHashFromCid(parentTsCid)
if err != nil {
return api.EthTx{}, err
@@ -826,6 +853,7 @@ func (a *EthModule) newEthTxFromFilecoinMessageLookup(ctx context.Context, msgLo
To: toAddr,
Value: api.EthBigInt(msg.Value),
Type: api.EthUint64(2),
TransactionIndex: api.EthUint64(txIdx),
Gas: api.EthUint64(msg.GasLimit),
MaxFeePerGas: api.EthBigInt(msg.GasFeeCap),
MaxPriorityFeePerGas: api.EthBigInt(msg.GasPremium),