Refactor EthBlockNumberOrHash and remove the number field
This commit is contained in:
@@ -62,7 +62,7 @@ func (e *EthModuleDummy) EthGetTransactionByHashLimited(ctx context.Context, txH
|
||||
return nil, ErrModuleDisabled
|
||||
}
|
||||
|
||||
func (e *EthModuleDummy) EthGetTransactionCount(ctx context.Context, sender ethtypes.EthAddress, blkParam ethtypes.EthBlockParamByNumberOrHash) (ethtypes.EthUint64, error) {
|
||||
func (e *EthModuleDummy) EthGetTransactionCount(ctx context.Context, sender ethtypes.EthAddress, blkParam ethtypes.EthBlockNumberOrHash) (ethtypes.EthUint64, error) {
|
||||
return 0, ErrModuleDisabled
|
||||
}
|
||||
|
||||
@@ -82,15 +82,15 @@ func (e *EthModuleDummy) EthGetTransactionByBlockNumberAndIndex(ctx context.Cont
|
||||
return ethtypes.EthTx{}, ErrModuleDisabled
|
||||
}
|
||||
|
||||
func (e *EthModuleDummy) EthGetCode(ctx context.Context, address ethtypes.EthAddress, blkParam ethtypes.EthBlockParamByNumberOrHash) (ethtypes.EthBytes, error) {
|
||||
func (e *EthModuleDummy) EthGetCode(ctx context.Context, address ethtypes.EthAddress, blkParam ethtypes.EthBlockNumberOrHash) (ethtypes.EthBytes, error) {
|
||||
return nil, ErrModuleDisabled
|
||||
}
|
||||
|
||||
func (e *EthModuleDummy) EthGetStorageAt(ctx context.Context, address ethtypes.EthAddress, position ethtypes.EthBytes, blkParam ethtypes.EthBlockParamByNumberOrHash) (ethtypes.EthBytes, error) {
|
||||
func (e *EthModuleDummy) EthGetStorageAt(ctx context.Context, address ethtypes.EthAddress, position ethtypes.EthBytes, blkParam ethtypes.EthBlockNumberOrHash) (ethtypes.EthBytes, error) {
|
||||
return nil, ErrModuleDisabled
|
||||
}
|
||||
|
||||
func (e *EthModuleDummy) EthGetBalance(ctx context.Context, address ethtypes.EthAddress, blkParam ethtypes.EthBlockParamByNumberOrHash) (ethtypes.EthBigInt, error) {
|
||||
func (e *EthModuleDummy) EthGetBalance(ctx context.Context, address ethtypes.EthAddress, blkParam ethtypes.EthBlockNumberOrHash) (ethtypes.EthBigInt, error) {
|
||||
return ethtypes.EthBigIntZero, ErrModuleDisabled
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ func (e *EthModuleDummy) EthEstimateGas(ctx context.Context, tx ethtypes.EthCall
|
||||
return 0, ErrModuleDisabled
|
||||
}
|
||||
|
||||
func (e *EthModuleDummy) EthCall(ctx context.Context, tx ethtypes.EthCall, blkParam ethtypes.EthBlockParamByNumberOrHash) (ethtypes.EthBytes, error) {
|
||||
func (e *EthModuleDummy) EthCall(ctx context.Context, tx ethtypes.EthCall, blkParam ethtypes.EthBlockNumberOrHash) (ethtypes.EthBytes, error) {
|
||||
return nil, ErrModuleDisabled
|
||||
}
|
||||
|
||||
|
||||
+27
-38
@@ -59,12 +59,12 @@ type EthModuleAPI interface {
|
||||
EthGetTransactionByHashLimited(ctx context.Context, txHash *ethtypes.EthHash, limit abi.ChainEpoch) (*ethtypes.EthTx, error)
|
||||
EthGetMessageCidByTransactionHash(ctx context.Context, txHash *ethtypes.EthHash) (*cid.Cid, error)
|
||||
EthGetTransactionHashByCid(ctx context.Context, cid cid.Cid) (*ethtypes.EthHash, error)
|
||||
EthGetTransactionCount(ctx context.Context, sender ethtypes.EthAddress, blkParam ethtypes.EthBlockParamByNumberOrHash) (ethtypes.EthUint64, error)
|
||||
EthGetTransactionCount(ctx context.Context, sender ethtypes.EthAddress, blkParam ethtypes.EthBlockNumberOrHash) (ethtypes.EthUint64, error)
|
||||
EthGetTransactionReceipt(ctx context.Context, txHash ethtypes.EthHash) (*api.EthTxReceipt, error)
|
||||
EthGetTransactionReceiptLimited(ctx context.Context, txHash ethtypes.EthHash, limit abi.ChainEpoch) (*api.EthTxReceipt, error)
|
||||
EthGetCode(ctx context.Context, address ethtypes.EthAddress, blkParam ethtypes.EthBlockParamByNumberOrHash) (ethtypes.EthBytes, error)
|
||||
EthGetStorageAt(ctx context.Context, address ethtypes.EthAddress, position ethtypes.EthBytes, blkParam ethtypes.EthBlockParamByNumberOrHash) (ethtypes.EthBytes, error)
|
||||
EthGetBalance(ctx context.Context, address ethtypes.EthAddress, blkParam ethtypes.EthBlockParamByNumberOrHash) (ethtypes.EthBigInt, error)
|
||||
EthGetCode(ctx context.Context, address ethtypes.EthAddress, blkParam ethtypes.EthBlockNumberOrHash) (ethtypes.EthBytes, error)
|
||||
EthGetStorageAt(ctx context.Context, address ethtypes.EthAddress, position ethtypes.EthBytes, blkParam ethtypes.EthBlockNumberOrHash) (ethtypes.EthBytes, error)
|
||||
EthGetBalance(ctx context.Context, address ethtypes.EthAddress, blkParam ethtypes.EthBlockNumberOrHash) (ethtypes.EthBigInt, error)
|
||||
EthFeeHistory(ctx context.Context, p jsonrpc.RawParams) (ethtypes.EthFeeHistory, error)
|
||||
EthChainId(ctx context.Context) (ethtypes.EthUint64, error)
|
||||
EthSyncing(ctx context.Context) (ethtypes.EthSyncingResult, error)
|
||||
@@ -73,7 +73,7 @@ type EthModuleAPI interface {
|
||||
EthProtocolVersion(ctx context.Context) (ethtypes.EthUint64, error)
|
||||
EthGasPrice(ctx context.Context) (ethtypes.EthBigInt, error)
|
||||
EthEstimateGas(ctx context.Context, tx ethtypes.EthCall) (ethtypes.EthUint64, error)
|
||||
EthCall(ctx context.Context, tx ethtypes.EthCall, blkParam ethtypes.EthBlockParamByNumberOrHash) (ethtypes.EthBytes, error)
|
||||
EthCall(ctx context.Context, tx ethtypes.EthCall, blkParam ethtypes.EthBlockNumberOrHash) (ethtypes.EthBytes, error)
|
||||
EthMaxPriorityFeePerGas(ctx context.Context) (ethtypes.EthBigInt, error)
|
||||
EthSendRawTransaction(ctx context.Context, rawTx ethtypes.EthBytes) (ethtypes.EthHash, error)
|
||||
Web3ClientVersion(ctx context.Context) (string, error)
|
||||
@@ -241,7 +241,7 @@ func (a *EthModule) EthGetBlockByHash(ctx context.Context, blkHash ethtypes.EthH
|
||||
return newEthBlockFromFilecoinTipSet(ctx, ts, fullTxInfo, a.Chain, a.StateAPI)
|
||||
}
|
||||
|
||||
func (a *EthModule) getTipsetByEthBlockNumberOrHash(ctx context.Context, blkParam ethtypes.EthBlockParamByNumberOrHash) (*types.TipSet, error) {
|
||||
func (a *EthModule) getTipsetByEthBlockNumberOrHash(ctx context.Context, blkParam ethtypes.EthBlockNumberOrHash) (*types.TipSet, error) {
|
||||
head := a.Chain.GetHeaviestTipSet()
|
||||
|
||||
predefined := blkParam.PredefinedBlock
|
||||
@@ -261,8 +261,8 @@ func (a *EthModule) getTipsetByEthBlockNumberOrHash(ctx context.Context, blkPara
|
||||
}
|
||||
}
|
||||
|
||||
// utility function to validate a tipset by height and return it
|
||||
returnAndValidateTipsetFunc := func(height abi.ChainEpoch) (*types.TipSet, error) {
|
||||
if blkParam.BlockNumber != nil {
|
||||
height := abi.ChainEpoch(*blkParam.BlockNumber)
|
||||
if height > head.Height()-1 {
|
||||
return nil, fmt.Errorf("requested a future epoch (beyond 'latest')")
|
||||
}
|
||||
@@ -273,34 +273,23 @@ func (a *EthModule) getTipsetByEthBlockNumberOrHash(ctx context.Context, blkPara
|
||||
return ts, nil
|
||||
}
|
||||
|
||||
if blkParam.Number != nil {
|
||||
return returnAndValidateTipsetFunc(abi.ChainEpoch(*blkParam.Number))
|
||||
}
|
||||
|
||||
if blkParam.BlockNumber != nil {
|
||||
return returnAndValidateTipsetFunc(abi.ChainEpoch(*blkParam.BlockNumber))
|
||||
}
|
||||
|
||||
if blkParam.BlockHash != nil {
|
||||
ts, err := a.Chain.GetTipSetByCid(ctx, blkParam.BlockHash.ToCid())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get tipset by hash: %v", err)
|
||||
}
|
||||
|
||||
// verify that the tipset is in the canonical chain
|
||||
if blkParam.RequireCanonical {
|
||||
// walk back the current chain (our head) until we reach targetHeight and validate the block hash
|
||||
currTs := head
|
||||
for {
|
||||
if currTs.Equals(ts) {
|
||||
return ts, nil
|
||||
} else if currTs.Height() < ts.Height() {
|
||||
return nil, fmt.Errorf("could not find block hash %s in canonical chain", blkParam.BlockHash.ToCid())
|
||||
}
|
||||
// walk up the current chain (our head) until we reach ts.Height()
|
||||
walkTs, err := a.ChainAPI.ChainGetTipSetByHeight(ctx, ts.Height(), head.Key())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get tipset at height: %v", ts.Height())
|
||||
}
|
||||
|
||||
currTs, err = a.Chain.LoadTipSet(ctx, currTs.Parents())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to load tipset: %v", err)
|
||||
}
|
||||
// verify that it equals the expected tipset
|
||||
if !walkTs.Equals(ts) {
|
||||
return nil, fmt.Errorf("tipset is not canonical")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -451,7 +440,7 @@ func (a *EthModule) EthGetTransactionHashByCid(ctx context.Context, cid cid.Cid)
|
||||
return &hash, err
|
||||
}
|
||||
|
||||
func (a *EthModule) EthGetTransactionCount(ctx context.Context, sender ethtypes.EthAddress, blkParam ethtypes.EthBlockParamByNumberOrHash) (ethtypes.EthUint64, error) {
|
||||
func (a *EthModule) EthGetTransactionCount(ctx context.Context, sender ethtypes.EthAddress, blkParam ethtypes.EthBlockNumberOrHash) (ethtypes.EthUint64, error) {
|
||||
addr, err := sender.ToFilecoinAddress()
|
||||
if err != nil {
|
||||
return ethtypes.EthUint64(0), nil
|
||||
@@ -459,7 +448,7 @@ func (a *EthModule) EthGetTransactionCount(ctx context.Context, sender ethtypes.
|
||||
|
||||
ts, err := a.getTipsetByEthBlockNumberOrHash(ctx, blkParam)
|
||||
if err != nil {
|
||||
return ethtypes.EthUint64(0), xerrors.Errorf("failed to process block param: %s; %w", blkParam, err)
|
||||
return ethtypes.EthUint64(0), xerrors.Errorf("failed to process block param: %v; %w", blkParam, err)
|
||||
}
|
||||
|
||||
// First, handle the case where the "sender" is an EVM actor.
|
||||
@@ -539,7 +528,7 @@ func (a *EthAPI) EthGetTransactionByBlockNumberAndIndex(context.Context, ethtype
|
||||
}
|
||||
|
||||
// EthGetCode returns string value of the compiled bytecode
|
||||
func (a *EthModule) EthGetCode(ctx context.Context, ethAddr ethtypes.EthAddress, blkParam ethtypes.EthBlockParamByNumberOrHash) (ethtypes.EthBytes, error) {
|
||||
func (a *EthModule) EthGetCode(ctx context.Context, ethAddr ethtypes.EthAddress, blkParam ethtypes.EthBlockNumberOrHash) (ethtypes.EthBytes, error) {
|
||||
to, err := ethAddr.ToFilecoinAddress()
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("cannot get Filecoin address: %w", err)
|
||||
@@ -547,7 +536,7 @@ func (a *EthModule) EthGetCode(ctx context.Context, ethAddr ethtypes.EthAddress,
|
||||
|
||||
ts, err := a.getTipsetByEthBlockNumberOrHash(ctx, blkParam)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("failed to process block param: %s; %w", blkParam, err)
|
||||
return nil, xerrors.Errorf("failed to process block param: %v; %w", blkParam, err)
|
||||
}
|
||||
|
||||
// StateManager.Call will panic if there is no parent
|
||||
@@ -623,10 +612,10 @@ func (a *EthModule) EthGetCode(ctx context.Context, ethAddr ethtypes.EthAddress,
|
||||
return blk.RawData(), nil
|
||||
}
|
||||
|
||||
func (a *EthModule) EthGetStorageAt(ctx context.Context, ethAddr ethtypes.EthAddress, position ethtypes.EthBytes, blkParam ethtypes.EthBlockParamByNumberOrHash) (ethtypes.EthBytes, error) {
|
||||
func (a *EthModule) EthGetStorageAt(ctx context.Context, ethAddr ethtypes.EthAddress, position ethtypes.EthBytes, blkParam ethtypes.EthBlockNumberOrHash) (ethtypes.EthBytes, error) {
|
||||
ts, err := a.getTipsetByEthBlockNumberOrHash(ctx, blkParam)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("failed to process block param: %s; %w", blkParam, err)
|
||||
return nil, xerrors.Errorf("failed to process block param: %v; %w", blkParam, err)
|
||||
}
|
||||
|
||||
l := len(position)
|
||||
@@ -714,7 +703,7 @@ func (a *EthModule) EthGetStorageAt(ctx context.Context, ethAddr ethtypes.EthAdd
|
||||
return ethtypes.EthBytes(ret), nil
|
||||
}
|
||||
|
||||
func (a *EthModule) EthGetBalance(ctx context.Context, address ethtypes.EthAddress, blkParam ethtypes.EthBlockParamByNumberOrHash) (ethtypes.EthBigInt, error) {
|
||||
func (a *EthModule) EthGetBalance(ctx context.Context, address ethtypes.EthAddress, blkParam ethtypes.EthBlockNumberOrHash) (ethtypes.EthBigInt, error) {
|
||||
filAddr, err := address.ToFilecoinAddress()
|
||||
if err != nil {
|
||||
return ethtypes.EthBigInt{}, err
|
||||
@@ -722,7 +711,7 @@ func (a *EthModule) EthGetBalance(ctx context.Context, address ethtypes.EthAddre
|
||||
|
||||
ts, err := a.getTipsetByEthBlockNumberOrHash(ctx, blkParam)
|
||||
if err != nil {
|
||||
return ethtypes.EthBigInt{}, xerrors.Errorf("failed to process block param: %s; %w", blkParam, err)
|
||||
return ethtypes.EthBigInt{}, xerrors.Errorf("failed to process block param: %v; %w", blkParam, err)
|
||||
}
|
||||
|
||||
st, _, err := a.StateManager.TipSetState(ctx, ts)
|
||||
@@ -1181,7 +1170,7 @@ func ethGasSearch(
|
||||
return -1, xerrors.Errorf("message execution failed: exit %s, reason: %s", res.MsgRct.ExitCode, res.Error)
|
||||
}
|
||||
|
||||
func (a *EthModule) EthCall(ctx context.Context, tx ethtypes.EthCall, blkParam ethtypes.EthBlockParamByNumberOrHash) (ethtypes.EthBytes, error) {
|
||||
func (a *EthModule) EthCall(ctx context.Context, tx ethtypes.EthCall, blkParam ethtypes.EthBlockNumberOrHash) (ethtypes.EthBytes, error) {
|
||||
msg, err := a.ethCallToFilecoinMessage(ctx, tx)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("failed to convert ethcall to filecoin message: %w", err)
|
||||
@@ -1189,7 +1178,7 @@ func (a *EthModule) EthCall(ctx context.Context, tx ethtypes.EthCall, blkParam e
|
||||
|
||||
ts, err := a.getTipsetByEthBlockNumberOrHash(ctx, blkParam)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("failed to process block param: %s; %w", blkParam, err)
|
||||
return nil, xerrors.Errorf("failed to process block param: %v; %w", blkParam, err)
|
||||
}
|
||||
|
||||
invokeResult, err := a.applyMessage(ctx, msg, ts.Key())
|
||||
|
||||
Reference in New Issue
Block a user