diff --git a/api/api_full.go b/api/api_full.go index cf2bb0919c..5d751379be 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -768,7 +768,7 @@ type FullNode interface { // MethodGroup: Eth // These methods are used for Ethereum-compatible JSON-RPC calls // - // # Execution model reconciliation + // ### Execution model reconciliation // // Ethereum relies on an immediate block-based execution model. The block that includes // a transaction is also the block that executes it. Each block specifies the state root diff --git a/documentation/en/api-v1-unstable-methods.md b/documentation/en/api-v1-unstable-methods.md index 6eef98e10b..7089dcb066 100644 --- a/documentation/en/api-v1-unstable-methods.md +++ b/documentation/en/api-v1-unstable-methods.md @@ -1326,7 +1326,7 @@ Response: `{}` ## Eth These methods are used for Ethereum-compatible JSON-RPC calls -# Execution model reconciliation +### Execution model reconciliation Ethereum relies on an immediate block-based execution model. The block that includes a transaction is also the block that executes it. Each block specifies the state root diff --git a/node/impl/eth/basic.go b/node/impl/eth/basic.go index 3a51e2dc09..8c2288758e 100644 --- a/node/impl/eth/basic.go +++ b/node/impl/eth/basic.go @@ -2,14 +2,13 @@ package eth import ( "context" - "errors" - "fmt" "strconv" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/build/buildconstants" "github.com/filecoin-project/lotus/chain/types/ethtypes" + "golang.org/x/xerrors" ) type EthBasic interface { @@ -69,11 +68,11 @@ func (e *ethBasic) EthProtocolVersion(ctx context.Context) (ethtypes.EthUint64, func (e *ethBasic) EthSyncing(ctx context.Context) (ethtypes.EthSyncingResult, error) { state, err := e.syncAPI.SyncState(ctx) if err != nil { - return ethtypes.EthSyncingResult{}, fmt.Errorf("failed calling SyncState: %w", err) + return ethtypes.EthSyncingResult{}, xerrors.Errorf("failed calling SyncState: %w", err) } if len(state.ActiveSyncs) == 0 { - return ethtypes.EthSyncingResult{}, errors.New("no active syncs, try again") + return ethtypes.EthSyncingResult{}, xerrors.New("no active syncs, try again") } working := -1 @@ -89,7 +88,7 @@ func (e *ethBasic) EthSyncing(ctx context.Context) (ethtypes.EthSyncingResult, e ss := state.ActiveSyncs[working] if ss.Base == nil || ss.Target == nil { - return ethtypes.EthSyncingResult{}, errors.New("missing syncing information, try again") + return ethtypes.EthSyncingResult{}, xerrors.New("missing syncing information, try again") } res := ethtypes.EthSyncingResult{ diff --git a/node/impl/eth/events.go b/node/impl/eth/events.go index 4939772bfa..320fbd4488 100644 --- a/node/impl/eth/events.go +++ b/node/impl/eth/events.go @@ -229,7 +229,7 @@ func (e *ethEvents) EthGetFilterChanges(ctx context.Context, id ethtypes.EthFilt return ethFilterResultFromMessages(fc.TakeCollectedMessages(ctx)) } - return nil, xerrors.Errorf("unknown filter type") + return nil, xerrors.New("unknown filter type") } func (e *ethEvents) EthGetFilterLogs(ctx context.Context, id ethtypes.EthFilterID) (*ethtypes.EthFilterResult, error) { @@ -247,7 +247,7 @@ func (e *ethEvents) EthGetFilterLogs(ctx context.Context, id ethtypes.EthFilterI return ethFilterResultFromEvents(ctx, fc.TakeCollectedEvents(ctx), e.chainStore, e.stateManager) } - return nil, xerrors.Errorf("wrong filter type") + return nil, xerrors.New("wrong filter type") } func (e *ethEvents) EthSubscribe(ctx context.Context, p jsonrpc.RawParams) (ethtypes.EthSubscriptionID, error) { @@ -262,7 +262,7 @@ func (e *ethEvents) EthSubscribe(ctx context.Context, p jsonrpc.RawParams) (etht ethCb, ok := jsonrpc.ExtractReverseClient[api.EthSubscriberMethods](ctx) if !ok { - return ethtypes.EthSubscriptionID{}, xerrors.Errorf("connection doesn't support callbacks") + return ethtypes.EthSubscriptionID{}, xerrors.New("connection doesn't support callbacks") } sub, err := e.subscriptionManager.StartSubscription(e.subscribtionCtx, ethCb.EthSubscription, e.uninstallFilter) @@ -615,11 +615,11 @@ func parseBlockRange(heaviest abi.ChainEpoch, fromBlock, toBlock *string, maxRan minHeight = 0 } else { if !strings.HasPrefix(*fromBlock, "0x") { - return 0, 0, xerrors.Errorf("FromBlock is not a hex") + return 0, 0, xerrors.New("FromBlock is not a hex") } epoch, err := ethtypes.EthUint64FromHex(*fromBlock) if err != nil { - return 0, 0, xerrors.Errorf("invalid epoch") + return 0, 0, xerrors.New("invalid epoch") } minHeight = abi.ChainEpoch(epoch) } @@ -631,11 +631,11 @@ func parseBlockRange(heaviest abi.ChainEpoch, fromBlock, toBlock *string, maxRan maxHeight = 0 } else { if !strings.HasPrefix(*toBlock, "0x") { - return 0, 0, xerrors.Errorf("ToBlock is not a hex") + return 0, 0, xerrors.New("ToBlock is not a hex") } epoch, err := ethtypes.EthUint64FromHex(*toBlock) if err != nil { - return 0, 0, xerrors.Errorf("invalid epoch") + return 0, 0, xerrors.New("invalid epoch") } maxHeight = abi.ChainEpoch(epoch) } @@ -680,7 +680,7 @@ func (e *ethEvents) parseEthFilterSpec(filterSpec *ethtypes.EthFilterSpec) (*par if filterSpec.BlockHash != nil { if filterSpec.FromBlock != nil || filterSpec.ToBlock != nil { - return nil, xerrors.Errorf("must not specify block hash and from/to block") + return nil, xerrors.New("must not specify block hash and from/to block") } tipsetCid = filterSpec.BlockHash.ToCid() @@ -747,7 +747,7 @@ func (e *ethEvents) uninstallFilter(ctx context.Context, f filter.Filter) error return err } default: - return xerrors.Errorf("unknown filter type") + return xerrors.New("unknown filter type") } return e.filterStore.Remove(ctx, f.ID()) diff --git a/node/impl/eth/gas.go b/node/impl/eth/gas.go index 8380da9e95..2055af242a 100644 --- a/node/impl/eth/gas.go +++ b/node/impl/eth/gas.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "errors" - "fmt" "os" "sort" @@ -81,21 +80,21 @@ func (e *ethGas) EthFeeHistory(ctx context.Context, p jsonrpc.RawParams) (ethtyp return ethtypes.EthFeeHistory{}, xerrors.Errorf("decoding params: %w", err) } if params.BlkCount > 1024 { - return ethtypes.EthFeeHistory{}, fmt.Errorf("block count should be smaller than 1024") + return ethtypes.EthFeeHistory{}, xerrors.New("block count should be smaller than 1024") } rewardPercentiles := make([]float64, 0) if params.RewardPercentiles != nil { if len(*params.RewardPercentiles) > maxEthFeeHistoryRewardPercentiles { - return ethtypes.EthFeeHistory{}, errors.New("length of the reward percentile array cannot be greater than 100") + return ethtypes.EthFeeHistory{}, xerrors.New("length of the reward percentile array cannot be greater than 100") } rewardPercentiles = append(rewardPercentiles, *params.RewardPercentiles...) } for i, rp := range rewardPercentiles { if rp < 0 || rp > 100 { - return ethtypes.EthFeeHistory{}, fmt.Errorf("invalid reward percentile: %f should be between 0 and 100", rp) + return ethtypes.EthFeeHistory{}, xerrors.Errorf("invalid reward percentile: %f should be between 0 and 100", rp) } if i > 0 && rp < rewardPercentiles[i-1] { - return ethtypes.EthFeeHistory{}, fmt.Errorf("invalid reward percentile: %f should be larger than %f", rp, rewardPercentiles[i-1]) + return ethtypes.EthFeeHistory{}, xerrors.Errorf("invalid reward percentile: %f should be larger than %f", rp, rewardPercentiles[i-1]) } } @@ -147,7 +146,7 @@ func (e *ethGas) EthFeeHistory(ctx context.Context, p jsonrpc.RawParams) (ethtyp parentTsKey := ts.Parents() ts, err = e.chainStore.LoadTipSet(ctx, parentTsKey) if err != nil { - return ethtypes.EthFeeHistory{}, fmt.Errorf("cannot load tipset key: %v", parentTsKey) + return ethtypes.EthFeeHistory{}, xerrors.Errorf("cannot load tipset key: %v", parentTsKey) } } diff --git a/node/impl/eth/lookup.go b/node/impl/eth/lookup.go index 24a305ab51..4c09a2649e 100644 --- a/node/impl/eth/lookup.go +++ b/node/impl/eth/lookup.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "errors" - "fmt" "golang.org/x/xerrors" @@ -69,7 +68,7 @@ func (e *ethLookup) EthGetCode(ctx context.Context, ethAddr ethtypes.EthAddress, // StateManager.Call will panic if there is no parent if ts.Height() == 0 { - return nil, xerrors.Errorf("block param must not specify genesis block") + return nil, xerrors.New("block param must not specify genesis block") } actor, err := e.stateManager.LoadActor(ctx, to, ts) @@ -115,7 +114,7 @@ func (e *ethLookup) EthGetCode(ctx context.Context, ethAddr ethtypes.EthAddress, } if res.MsgRct == nil { - return nil, fmt.Errorf("no message receipt") + return nil, xerrors.New("no message receipt") } if res.MsgRct.ExitCode.IsError() { @@ -124,7 +123,7 @@ func (e *ethLookup) EthGetCode(ctx context.Context, ethAddr ethtypes.EthAddress, var getBytecodeReturn evm.GetBytecodeReturn if err := getBytecodeReturn.UnmarshalCBOR(bytes.NewReader(res.MsgRct.Return)); err != nil { - return nil, fmt.Errorf("failed to decode EVM bytecode CID: %w", err) + return nil, xerrors.Errorf("failed to decode EVM bytecode CID: %w", err) } // The contract has selfdestructed, so the code is "empty". @@ -134,7 +133,7 @@ func (e *ethLookup) EthGetCode(ctx context.Context, ethAddr ethtypes.EthAddress, blk, err := e.stateBlockstore.Get(ctx, *getBytecodeReturn.Cid) if err != nil { - return nil, fmt.Errorf("failed to get EVM bytecode: %w", err) + return nil, xerrors.Errorf("failed to get EVM bytecode: %w", err) } return blk.RawData(), nil @@ -148,7 +147,7 @@ func (e *ethLookup) EthGetStorageAt(ctx context.Context, ethAddr ethtypes.EthAdd pl := len(position) if pl > 32 { - return nil, fmt.Errorf("supplied storage key is too long") + return nil, xerrors.New("supplied storage key is too long") } // pad with zero bytes if smaller than 32 bytes @@ -162,7 +161,7 @@ func (e *ethLookup) EthGetStorageAt(ctx context.Context, ethAddr ethtypes.EthAdd // use the system actor as the caller from, err := address.NewIDAddress(0) if err != nil { - return nil, fmt.Errorf("failed to construct system sender address: %w", err) + return nil, xerrors.Errorf("failed to construct system sender address: %w", err) } actor, err := e.stateManager.LoadActor(ctx, to, ts) @@ -181,7 +180,7 @@ func (e *ethLookup) EthGetStorageAt(ctx context.Context, ethAddr ethtypes.EthAdd StorageKey: *(*[32]byte)(position), }) if err != nil { - return nil, fmt.Errorf("failed to serialize parameters: %w", err) + return nil, xerrors.Errorf("failed to serialize parameters: %w", err) } msg := &types.Message{ @@ -213,7 +212,7 @@ func (e *ethLookup) EthGetStorageAt(ctx context.Context, ethAddr ethtypes.EthAdd } if res.MsgRct == nil { - return nil, xerrors.Errorf("no message receipt") + return nil, xerrors.New("no message receipt") } if res.MsgRct.ExitCode.IsError() { @@ -264,11 +263,11 @@ func (e *ethLookup) EthChainId(ctx context.Context) (ethtypes.EthUint64, error) func (e *ethLookup) EthSyncing(ctx context.Context) (ethtypes.EthSyncingResult, error) { state, err := e.syncAPI.SyncState(ctx) if err != nil { - return ethtypes.EthSyncingResult{}, fmt.Errorf("failed calling SyncState: %w", err) + return ethtypes.EthSyncingResult{}, xerrors.Errorf("failed calling SyncState: %w", err) } if len(state.ActiveSyncs) == 0 { - return ethtypes.EthSyncingResult{}, errors.New("no active syncs, try again") + return ethtypes.EthSyncingResult{}, xerrors.New("no active syncs, try again") } working := -1 @@ -284,7 +283,7 @@ func (e *ethLookup) EthSyncing(ctx context.Context) (ethtypes.EthSyncingResult, ss := state.ActiveSyncs[working] if ss.Base == nil || ss.Target == nil { - return ethtypes.EthSyncingResult{}, errors.New("missing syncing information, try again") + return ethtypes.EthSyncingResult{}, xerrors.New("missing syncing information, try again") } res := ethtypes.EthSyncingResult{ diff --git a/node/impl/eth/subscriptions.go b/node/impl/eth/subscriptions.go index e46e4bc2ac..d1a5150300 100644 --- a/node/impl/eth/subscriptions.go +++ b/node/impl/eth/subscriptions.go @@ -75,7 +75,7 @@ func (e *EthSubscriptionManager) StopSubscription(ctx context.Context, id ethtyp sub, ok := e.subs[id] if !ok { - return xerrors.Errorf("subscription not found") + return xerrors.New("subscription not found") } sub.stop() delete(e.subs, id) diff --git a/node/impl/eth/trace.go b/node/impl/eth/trace.go index 6f0beb0218..d1b0dfb49f 100644 --- a/node/impl/eth/trace.go +++ b/node/impl/eth/trace.go @@ -130,7 +130,7 @@ func (e *ethTrace) EthTraceBlock(ctx context.Context, blkNum string) ([]*ethtype func (e *ethTrace) EthTraceReplayBlockTransactions(ctx context.Context, blkNum string, traceTypes []string) ([]*ethtypes.EthTraceReplayBlockTransaction, error) { if len(traceTypes) != 1 || traceTypes[0] != "trace" { - return nil, fmt.Errorf("only 'trace' is supported") + return nil, xerrors.New("only 'trace' is supported") } ts, err := getTipsetByBlockNumber(ctx, e.chainStore, blkNum, true) if err != nil { @@ -207,12 +207,12 @@ func (e *ethTrace) EthTraceTransaction(ctx context.Context, txHash string) ([]*e } if tx == nil { - return nil, xerrors.Errorf("transaction not found") + return nil, xerrors.New("transaction not found") } // tx.BlockNumber is nil when the transaction is still in the mpool/pending if tx.BlockNumber == nil { - return nil, xerrors.Errorf("no trace for pending transactions") + return nil, xerrors.New("no trace for pending transactions") } blockTraces, err := e.EthTraceBlock(ctx, strconv.FormatUint(uint64(*tx.BlockNumber), 10)) @@ -251,13 +251,13 @@ func (e *ethTrace) EthTraceFilter(ctx context.Context, filter ethtypes.EthTraceF switch blockValue { case "earliest": - return 0, xerrors.Errorf("block param \"earliest\" is not supported") + return 0, xerrors.New("block param \"earliest\" is not supported") case "pending": return ethtypes.EthUint64(head.Height()), nil case "latest": parent, err := e.chainStore.GetTipSetFromKey(ctx, head.Parents()) if err != nil { - return 0, fmt.Errorf("cannot get parent tipset") + return 0, xerrors.New("cannot get parent tipset") } return ethtypes.EthUint64(parent.Height()), nil case "safe": @@ -310,7 +310,7 @@ func (e *ethTrace) EthTraceFilter(ctx context.Context, filter ethtypes.EthTraceF for _, _blockTrace := range blockTraces { // Create a copy of blockTrace to avoid pointer quirks blockTrace := *_blockTrace - match, err := matchFilterCriteria(&blockTrace, filter, filter.FromAddress, filter.ToAddress) + match, err := matchFilterCriteria(&blockTrace, filter.FromAddress, filter.ToAddress) if err != nil { return nil, xerrors.Errorf("cannot match filter for block %d: %w", blkNum, err) } @@ -322,13 +322,7 @@ func (e *ethTrace) EthTraceFilter(ctx context.Context, filter ethtypes.EthTraceF continue } - txTrace := ethtypes.EthTraceFilterResult{ - EthTrace: blockTrace.EthTrace, - BlockHash: blockTrace.BlockHash, - BlockNumber: blockTrace.BlockNumber, - TransactionHash: blockTrace.TransactionHash, - TransactionPosition: blockTrace.TransactionPosition, - } + txTrace := ethtypes.EthTraceFilterResult(blockTrace) results = append(results, &txTrace) // If Count is specified, limit the results @@ -344,7 +338,7 @@ func (e *ethTrace) EthTraceFilter(ctx context.Context, filter ethtypes.EthTraceF } // matchFilterCriteria checks if a trace matches the filter criteria. -func matchFilterCriteria(trace *ethtypes.EthTraceBlock, filter ethtypes.EthTraceFilterCriteria, fromDecodedAddresses []ethtypes.EthAddress, toDecodedAddresses []ethtypes.EthAddress) (bool, error) { +func matchFilterCriteria(trace *ethtypes.EthTraceBlock, fromDecodedAddresses []ethtypes.EthAddress, toDecodedAddresses []ethtypes.EthAddress) (bool, error) { var traceTo ethtypes.EthAddress var traceFrom ethtypes.EthAddress @@ -352,23 +346,23 @@ func matchFilterCriteria(trace *ethtypes.EthTraceBlock, filter ethtypes.EthTrace case "call": action, ok := trace.Action.(*ethtypes.EthCallTraceAction) if !ok { - return false, xerrors.Errorf("invalid call trace action") + return false, xerrors.New("invalid call trace action") } traceTo = action.To traceFrom = action.From case "create": result, okResult := trace.Result.(*ethtypes.EthCreateTraceResult) if !okResult { - return false, xerrors.Errorf("invalid create trace result") + return false, xerrors.New("invalid create trace result") } action, okAction := trace.Action.(*ethtypes.EthCreateTraceAction) if !okAction { - return false, xerrors.Errorf("invalid create trace action") + return false, xerrors.New("invalid create trace action") } if result.Address == nil { - return false, xerrors.Errorf("address is nil in create trace result") + return false, xerrors.New("address is nil in create trace result") } traceTo = *result.Address @@ -733,7 +727,7 @@ func traceNativeCreate(env *environment, addr []int, et *types.ExecutionTrace) ( // something, we have a bug in our tracing logic or a mismatch between our // tracing logic and the actors. if et.MsgRct.ExitCode.IsSuccess() { - return nil, nil, xerrors.Errorf("successful Exec/Exec4 call failed to call a constructor") + return nil, nil, xerrors.New("successful Exec/Exec4 call failed to call a constructor") } // Otherwise, this can happen if creation fails early (bad params, // out of gas, contract already exists, etc.). The EVM wouldn't @@ -752,7 +746,7 @@ func traceNativeCreate(env *environment, addr []int, et *types.ExecutionTrace) ( // actor. I'm catching this here because it likely means that there's a bug // in our trace-conversion logic. if et.Msg.Method == builtin.MethodsInit.Exec4 { - return nil, nil, xerrors.Errorf("direct call to Exec4 successfully called a constructor!") + return nil, nil, xerrors.New("direct call to Exec4 successfully called a constructor!") } var output ethtypes.EthBytes @@ -866,7 +860,7 @@ func traceEthCreate(env *environment, addr []int, et *types.ExecutionTrace) (*et // Same as the Init actor case above, see the comment there. if subTrace == nil { if et.MsgRct.ExitCode.IsSuccess() { - return nil, nil, xerrors.Errorf("successful Create/Create2 call failed to call a constructor") + return nil, nil, xerrors.New("successful Create/Create2 call failed to call a constructor") } return nil, nil, nil } @@ -952,7 +946,7 @@ func traceEVMPrivate(env *environment, addr []int, et *types.ExecutionTrace) (*e // (GetByteCode) and they are at the same level (same parent) // 3) Treat this as a delegate call to actor A. if env.lastByteCode == nil { - return nil, nil, xerrors.Errorf("unknown bytecode for delegate call") + return nil, nil, xerrors.New("unknown bytecode for delegate call") } if to := traceToAddress(et.InvokedActor); env.caller != to { diff --git a/node/impl/eth/transaction.go b/node/impl/eth/transaction.go index 97c603580e..da7fceb43f 100644 --- a/node/impl/eth/transaction.go +++ b/node/impl/eth/transaction.go @@ -3,7 +3,6 @@ package eth import ( "context" "errors" - "fmt" "github.com/hashicorp/golang-lru/arc/v2" "github.com/ipfs/go-cid" @@ -223,7 +222,7 @@ func (e *ethTransaction) EthGetTransactionByHashLimited(ctx context.Context, txH if err != nil { // inability to fetch mpool pending transactions is an internal node error // that needs to be reported as-is - return nil, fmt.Errorf("cannot get pending txs from mpool: %s", err) + return nil, xerrors.Errorf("cannot get pending txs from mpool: %s", err) } for _, p := range pending { @@ -237,12 +236,12 @@ func (e *ethTransaction) EthGetTransactionByHashLimited(ctx context.Context, txH // accounts. ethtx, err := ethtypes.EthTransactionFromSignedFilecoinMessage(p) if err != nil { - return nil, fmt.Errorf("could not convert Filecoin message into tx: %w", err) + return nil, xerrors.Errorf("could not convert Filecoin message into tx: %w", err) } tx, err := ethtx.ToEthTx(p) if err != nil { - return nil, fmt.Errorf("could not convert Eth transaction to EthTx: %w", err) + return nil, xerrors.Errorf("could not convert Eth transaction to EthTx: %w", err) } return &tx, nil diff --git a/node/impl/eth/utils.go b/node/impl/eth/utils.go index 70bb28b168..8bf24d8916 100644 --- a/node/impl/eth/utils.go +++ b/node/impl/eth/utils.go @@ -48,27 +48,27 @@ func getTipsetByEthBlockNumberOrHash(ctx context.Context, cp ChainStoreAPI, blkP predefined := blkParam.PredefinedBlock if predefined != nil { if *predefined == "earliest" { - return nil, fmt.Errorf("block param \"earliest\" is not supported") + return nil, xerrors.New("block param \"earliest\" is not supported") } else if *predefined == "pending" { return head, nil } else if *predefined == "latest" { parent, err := cp.GetTipSetFromKey(ctx, head.Parents()) if err != nil { - return nil, fmt.Errorf("cannot get parent tipset") + return nil, xerrors.New("cannot get parent tipset") } return parent, nil } - return nil, fmt.Errorf("unknown predefined block %s", *predefined) + return nil, xerrors.Errorf("unknown predefined block %s", *predefined) } if blkParam.BlockNumber != nil { height := abi.ChainEpoch(*blkParam.BlockNumber) if height > head.Height()-1 { - return nil, fmt.Errorf("requested a future epoch (beyond 'latest')") + return nil, xerrors.New("requested a future epoch (beyond 'latest')") } ts, err := cp.GetTipsetByHeight(ctx, height, head, true) if err != nil { - return nil, fmt.Errorf("cannot get tipset at height: %v", height) + return nil, xerrors.Errorf("cannot get tipset at height: %v", height) } return ts, nil } @@ -76,7 +76,7 @@ func getTipsetByEthBlockNumberOrHash(ctx context.Context, cp ChainStoreAPI, blkP if blkParam.BlockHash != nil { ts, err := cp.GetTipSetByCid(ctx, blkParam.BlockHash.ToCid()) if err != nil { - return nil, fmt.Errorf("cannot get tipset by hash: %v", err) + return nil, xerrors.Errorf("cannot get tipset by hash: %v", err) } // verify that the tipset is in the canonical chain @@ -84,19 +84,19 @@ func getTipsetByEthBlockNumberOrHash(ctx context.Context, cp ChainStoreAPI, blkP // walk up the current chain (our head) until we reach ts.Height() walkTs, err := cp.GetTipsetByHeight(ctx, ts.Height(), head, true) if err != nil { - return nil, fmt.Errorf("cannot get tipset at height: %v", ts.Height()) + return nil, xerrors.Errorf("cannot get tipset at height: %v", ts.Height()) } // verify that it equals the expected tipset if !walkTs.Equals(ts) { - return nil, fmt.Errorf("tipset is not canonical") + return nil, xerrors.New("tipset is not canonical") } } return ts, nil } - return nil, errors.New("invalid block param") + return nil, xerrors.New("invalid block param") } func ethCallToFilecoinMessage(ctx context.Context, tx ethtypes.EthCall) (*types.Message, error) { @@ -106,17 +106,17 @@ func ethCallToFilecoinMessage(ctx context.Context, tx ethtypes.EthCall) (*types. var err error from, err = (ethtypes.EthAddress{}).ToFilecoinAddress() if err != nil { - return nil, fmt.Errorf("failed to construct the ethereum system address: %w", err) + return nil, xerrors.Errorf("failed to construct the ethereum system address: %w", err) } } else { // The from address must be translatable to an f4 address. var err error from, err = tx.From.ToFilecoinAddress() if err != nil { - return nil, fmt.Errorf("failed to translate sender address (%s): %w", tx.From.String(), err) + return nil, xerrors.Errorf("failed to translate sender address (%s): %w", tx.From.String(), err) } if p := from.Protocol(); p != address.Delegated { - return nil, fmt.Errorf("expected a class 4 address, got: %d: %w", p, err) + return nil, xerrors.Errorf("expected a class 4 address, got: %d: %w", p, err) } } @@ -125,7 +125,7 @@ func ethCallToFilecoinMessage(ctx context.Context, tx ethtypes.EthCall) (*types. initcode := abi.CborBytes(tx.Data) params2, err := actors.SerializeParams(&initcode) if err != nil { - return nil, fmt.Errorf("failed to serialize params: %w", err) + return nil, xerrors.Errorf("failed to serialize params: %w", err) } params = params2 } @@ -583,7 +583,7 @@ func newEthTxFromMessageLookup( } } if txIdx < 0 { - return ethtypes.EthTx{}, fmt.Errorf("cannot find the msg in the tipset") + return ethtypes.EthTx{}, xerrors.New("cannot find the msg in the tipset") } } @@ -764,7 +764,7 @@ func encodeAsABIHelper(param1 uint64, param2 uint64, data []byte) []byte { func getTipsetByBlockNumber(ctx context.Context, cp ChainStoreAPI, blkParam string, strict bool) (*types.TipSet, error) { if blkParam == "earliest" { - return nil, fmt.Errorf("block param \"earliest\" is not supported") + return nil, xerrors.New("block param \"earliest\" is not supported") } head := cp.GetHeaviestTipSet() @@ -774,7 +774,7 @@ func getTipsetByBlockNumber(ctx context.Context, cp ChainStoreAPI, blkParam stri case "latest": parent, err := cp.GetTipSetFromKey(ctx, head.Parents()) if err != nil { - return nil, fmt.Errorf("cannot get parent tipset") + return nil, xerrors.New("cannot get parent tipset") } return parent, nil case "safe": @@ -782,7 +782,7 @@ func getTipsetByBlockNumber(ctx context.Context, cp ChainStoreAPI, blkParam stri safeHeight := latestHeight - ethtypes.SafeEpochDelay ts, err := cp.GetTipsetByHeight(ctx, safeHeight, head, true) if err != nil { - return nil, fmt.Errorf("cannot get tipset at height: %v", safeHeight) + return nil, xerrors.Errorf("cannot get tipset at height: %v", safeHeight) } return ts, nil case "finalized": @@ -790,21 +790,21 @@ func getTipsetByBlockNumber(ctx context.Context, cp ChainStoreAPI, blkParam stri safeHeight := latestHeight - policy.ChainFinality ts, err := cp.GetTipsetByHeight(ctx, safeHeight, head, true) if err != nil { - return nil, fmt.Errorf("cannot get tipset at height: %v", safeHeight) + return nil, xerrors.Errorf("cannot get tipset at height: %v", safeHeight) } return ts, nil default: var num ethtypes.EthUint64 err := num.UnmarshalJSON([]byte(`"` + blkParam + `"`)) if err != nil { - return nil, fmt.Errorf("cannot parse block number: %v", err) + return nil, xerrors.Errorf("cannot parse block number: %v", err) } if abi.ChainEpoch(num) > head.Height()-1 { - return nil, fmt.Errorf("requested a future epoch (beyond 'latest')") + return nil, xerrors.New("requested a future epoch (beyond 'latest')") } ts, err := cp.GetTipsetByHeight(ctx, abi.ChainEpoch(num), head, true) if err != nil { - return nil, fmt.Errorf("cannot get tipset at height: %v", num) + return nil, xerrors.Errorf("cannot get tipset at height: %v", num) } if strict && ts.Height() != abi.ChainEpoch(num) { return nil, api.NewErrNullRound(abi.ChainEpoch(num))