Merge remote-tracking branch 'origin/master' into feat/new-gw-methods
This commit is contained in:
commit
4ebc408a5a
142 files changed
+4519
-2818
No files matched your search
+6
-2
@@ -93,6 +93,7 @@ type TargetAPI interface {
|
||||
StateCirculatingSupply(context.Context, types.TipSetKey) (abi.TokenAmount, error)
|
||||
StateSectorGetInfo(ctx context.Context, maddr address.Address, n abi.SectorNumber, tsk types.TipSetKey) (*miner.SectorOnChainInfo, error)
|
||||
StateVerifiedClientStatus(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*abi.StoragePower, error)
|
||||
StateVerifierStatus(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*abi.StoragePower, error)
|
||||
StateVMCirculatingSupplyInternal(context.Context, types.TipSetKey) (api.CirculatingSupply, error)
|
||||
WalletBalance(context.Context, address.Address) (types.BigInt, error)
|
||||
|
||||
@@ -103,11 +104,11 @@ type TargetAPI interface {
|
||||
EthGetBlockTransactionCountByHash(ctx context.Context, blkHash ethtypes.EthHash) (ethtypes.EthUint64, error)
|
||||
EthGetBlockByHash(ctx context.Context, blkHash ethtypes.EthHash, fullTxInfo bool) (ethtypes.EthBlock, error)
|
||||
EthGetBlockByNumber(ctx context.Context, blkNum string, fullTxInfo bool) (ethtypes.EthBlock, error)
|
||||
EthGetTransactionByHash(ctx context.Context, txHash *ethtypes.EthHash) (*ethtypes.EthTx, error)
|
||||
EthGetTransactionByHashLimited(ctx context.Context, txHash *ethtypes.EthHash, limit abi.ChainEpoch) (*ethtypes.EthTx, error)
|
||||
EthGetTransactionHashByCid(ctx context.Context, cid cid.Cid) (*ethtypes.EthHash, error)
|
||||
EthGetMessageCidByTransactionHash(ctx context.Context, txHash *ethtypes.EthHash) (*cid.Cid, error)
|
||||
EthGetTransactionCount(ctx context.Context, sender ethtypes.EthAddress, blkOpt string) (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)
|
||||
EthGetTransactionByBlockHashAndIndex(ctx context.Context, blkHash ethtypes.EthHash, txIndex ethtypes.EthUint64) (ethtypes.EthTx, error)
|
||||
EthGetTransactionByBlockNumberAndIndex(ctx context.Context, blkNum ethtypes.EthUint64, txIndex ethtypes.EthUint64) (ethtypes.EthTx, error)
|
||||
EthGetCode(ctx context.Context, address ethtypes.EthAddress, blkOpt string) (ethtypes.EthBytes, error)
|
||||
@@ -196,6 +197,9 @@ func (gw *Node) checkTipset(ts *types.TipSet) error {
|
||||
}
|
||||
|
||||
func (gw *Node) checkTipsetHeight(ts *types.TipSet, h abi.ChainEpoch) error {
|
||||
if h > ts.Height() {
|
||||
return fmt.Errorf("tipset height in future")
|
||||
}
|
||||
tsBlock := ts.Blocks()[0]
|
||||
heightDelta := time.Duration(uint64(tsBlock.Height-h)*build.BlockDelaySecs) * time.Second
|
||||
timeAtHeight := time.Unix(int64(tsBlock.Timestamp), 0).Add(-heightDelta)
|
||||
|
||||
+61
-69
@@ -21,7 +21,7 @@ import (
|
||||
)
|
||||
|
||||
func (gw *Node) Web3ClientVersion(ctx context.Context) (string, error) {
|
||||
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
||||
if err := gw.limit(ctx, basicRateLimitTokens); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ func (gw *Node) EthAccounts(ctx context.Context) ([]ethtypes.EthAddress, error)
|
||||
}
|
||||
|
||||
func (gw *Node) EthBlockNumber(ctx context.Context) (ethtypes.EthUint64, error) {
|
||||
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
||||
if err := gw.limit(ctx, chainRateLimitTokens); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -80,40 +80,40 @@ func (gw *Node) checkBlkHash(ctx context.Context, blkHash ethtypes.EthHash) erro
|
||||
return gw.checkTipsetKey(ctx, tsk)
|
||||
}
|
||||
|
||||
func (gw *Node) checkBlkParam(ctx context.Context, blkParam string) error {
|
||||
func (gw *Node) checkBlkParam(ctx context.Context, blkParam string, lookback ethtypes.EthUint64) error {
|
||||
if blkParam == "earliest" {
|
||||
// also not supported in node impl
|
||||
return fmt.Errorf("block param \"earliest\" is not supported")
|
||||
}
|
||||
|
||||
switch blkParam {
|
||||
case "pending", "latest":
|
||||
// those will be recent enough, so we don't need to check
|
||||
return nil
|
||||
default:
|
||||
var num ethtypes.EthUint64
|
||||
err := num.UnmarshalJSON([]byte(`"` + blkParam + `"`))
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot parse block number: %v", err)
|
||||
}
|
||||
head, err := gw.target.ChainHead(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := gw.checkTipsetHeight(head, abi.ChainEpoch(num)); err != nil {
|
||||
return err
|
||||
}
|
||||
head, err := gw.target.ChainHead(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
var num ethtypes.EthUint64
|
||||
switch blkParam {
|
||||
case "pending", "latest":
|
||||
// Head is always ok.
|
||||
if lookback == 0 {
|
||||
return nil
|
||||
}
|
||||
// Can't look beyond 0 anyways.
|
||||
if lookback > ethtypes.EthUint64(head.Height()) {
|
||||
break
|
||||
}
|
||||
num = ethtypes.EthUint64(head.Height()) - lookback
|
||||
default:
|
||||
if err := num.UnmarshalJSON([]byte(`"` + blkParam + `"`)); err != nil {
|
||||
return fmt.Errorf("cannot parse block number: %v", err)
|
||||
}
|
||||
|
||||
}
|
||||
return gw.checkTipsetHeight(head, abi.ChainEpoch(num))
|
||||
}
|
||||
|
||||
func (gw *Node) EthGetBlockTransactionCountByHash(ctx context.Context, blkHash ethtypes.EthHash) (ethtypes.EthUint64, error) {
|
||||
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
if err := gw.checkBlkHash(ctx, blkHash); err != nil {
|
||||
if err := gw.limit(ctx, chainRateLimitTokens); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ func (gw *Node) EthGetBlockByNumber(ctx context.Context, blkNum string, fullTxIn
|
||||
return ethtypes.EthBlock{}, err
|
||||
}
|
||||
|
||||
if err := gw.checkBlkParam(ctx, blkNum); err != nil {
|
||||
if err := gw.checkBlkParam(ctx, blkNum, 0); err != nil {
|
||||
return ethtypes.EthBlock{}, err
|
||||
}
|
||||
|
||||
@@ -145,11 +145,21 @@ func (gw *Node) EthGetBlockByNumber(ctx context.Context, blkNum string, fullTxIn
|
||||
}
|
||||
|
||||
func (gw *Node) EthGetTransactionByHash(ctx context.Context, txHash *ethtypes.EthHash) (*ethtypes.EthTx, error) {
|
||||
return gw.target.EthGetTransactionByHashLimited(ctx, txHash, api.LookbackNoLimit)
|
||||
}
|
||||
|
||||
func (gw *Node) EthGetTransactionByHashLimited(ctx context.Context, txHash *ethtypes.EthHash, limit abi.ChainEpoch) (*ethtypes.EthTx, error) {
|
||||
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if limit == api.LookbackNoLimit {
|
||||
limit = gw.stateWaitLookbackLimit
|
||||
}
|
||||
if gw.stateWaitLookbackLimit != api.LookbackNoLimit && limit > gw.stateWaitLookbackLimit {
|
||||
limit = gw.stateWaitLookbackLimit
|
||||
}
|
||||
|
||||
return gw.target.EthGetTransactionByHash(ctx, txHash)
|
||||
return gw.target.EthGetTransactionByHashLimited(ctx, txHash, limit)
|
||||
}
|
||||
|
||||
func (gw *Node) EthGetTransactionHashByCid(ctx context.Context, cid cid.Cid) (*ethtypes.EthHash, error) {
|
||||
@@ -161,7 +171,7 @@ func (gw *Node) EthGetTransactionHashByCid(ctx context.Context, cid cid.Cid) (*e
|
||||
}
|
||||
|
||||
func (gw *Node) EthGetMessageCidByTransactionHash(ctx context.Context, txHash *ethtypes.EthHash) (*cid.Cid, error) {
|
||||
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
||||
if err := gw.limit(ctx, chainRateLimitTokens); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -173,7 +183,7 @@ func (gw *Node) EthGetTransactionCount(ctx context.Context, sender ethtypes.EthA
|
||||
return 0, err
|
||||
}
|
||||
|
||||
if err := gw.checkBlkParam(ctx, blkOpt); err != nil {
|
||||
if err := gw.checkBlkParam(ctx, blkOpt, 0); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -181,39 +191,21 @@ func (gw *Node) EthGetTransactionCount(ctx context.Context, sender ethtypes.EthA
|
||||
}
|
||||
|
||||
func (gw *Node) EthGetTransactionReceipt(ctx context.Context, txHash ethtypes.EthHash) (*api.EthTxReceipt, error) {
|
||||
return gw.EthGetTransactionReceiptLimited(ctx, txHash, api.LookbackNoLimit)
|
||||
}
|
||||
|
||||
func (gw *Node) EthGetTransactionReceiptLimited(ctx context.Context, txHash ethtypes.EthHash, limit abi.ChainEpoch) (*api.EthTxReceipt, error) {
|
||||
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return gw.target.EthGetTransactionReceipt(ctx, txHash)
|
||||
}
|
||||
|
||||
func (gw *Node) EthGetTransactionByBlockHashAndIndex(ctx context.Context, blkHash ethtypes.EthHash, txIndex ethtypes.EthUint64) (ethtypes.EthTx, error) {
|
||||
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
||||
return ethtypes.EthTx{}, err
|
||||
if limit == api.LookbackNoLimit {
|
||||
limit = gw.stateWaitLookbackLimit
|
||||
}
|
||||
if gw.stateWaitLookbackLimit != api.LookbackNoLimit && limit > gw.stateWaitLookbackLimit {
|
||||
limit = gw.stateWaitLookbackLimit
|
||||
}
|
||||
|
||||
if err := gw.checkBlkHash(ctx, blkHash); err != nil {
|
||||
return ethtypes.EthTx{}, err
|
||||
}
|
||||
|
||||
return gw.target.EthGetTransactionByBlockHashAndIndex(ctx, blkHash, txIndex)
|
||||
}
|
||||
|
||||
func (gw *Node) EthGetTransactionByBlockNumberAndIndex(ctx context.Context, blkNum ethtypes.EthUint64, txIndex ethtypes.EthUint64) (ethtypes.EthTx, error) {
|
||||
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
||||
return ethtypes.EthTx{}, err
|
||||
}
|
||||
|
||||
head, err := gw.target.ChainHead(ctx)
|
||||
if err != nil {
|
||||
return ethtypes.EthTx{}, err
|
||||
}
|
||||
if err := gw.checkTipsetHeight(head, abi.ChainEpoch(blkNum)); err != nil {
|
||||
return ethtypes.EthTx{}, err
|
||||
}
|
||||
|
||||
return gw.target.EthGetTransactionByBlockNumberAndIndex(ctx, blkNum, txIndex)
|
||||
return gw.target.EthGetTransactionReceiptLimited(ctx, txHash, limit)
|
||||
}
|
||||
|
||||
func (gw *Node) EthGetCode(ctx context.Context, address ethtypes.EthAddress, blkOpt string) (ethtypes.EthBytes, error) {
|
||||
@@ -221,7 +213,7 @@ func (gw *Node) EthGetCode(ctx context.Context, address ethtypes.EthAddress, blk
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := gw.checkBlkParam(ctx, blkOpt); err != nil {
|
||||
if err := gw.checkBlkParam(ctx, blkOpt, 0); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -233,7 +225,7 @@ func (gw *Node) EthGetStorageAt(ctx context.Context, address ethtypes.EthAddress
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := gw.checkBlkParam(ctx, blkParam); err != nil {
|
||||
if err := gw.checkBlkParam(ctx, blkParam, 0); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -245,7 +237,7 @@ func (gw *Node) EthGetBalance(ctx context.Context, address ethtypes.EthAddress,
|
||||
return ethtypes.EthBigInt(big.Zero()), err
|
||||
}
|
||||
|
||||
if err := gw.checkBlkParam(ctx, blkParam); err != nil {
|
||||
if err := gw.checkBlkParam(ctx, blkParam, 0); err != nil {
|
||||
return ethtypes.EthBigInt(big.Zero()), err
|
||||
}
|
||||
|
||||
@@ -253,7 +245,7 @@ func (gw *Node) EthGetBalance(ctx context.Context, address ethtypes.EthAddress,
|
||||
}
|
||||
|
||||
func (gw *Node) EthChainId(ctx context.Context) (ethtypes.EthUint64, error) {
|
||||
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
||||
if err := gw.limit(ctx, basicRateLimitTokens); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -269,7 +261,7 @@ func (gw *Node) NetVersion(ctx context.Context) (string, error) {
|
||||
}
|
||||
|
||||
func (gw *Node) NetListening(ctx context.Context) (bool, error) {
|
||||
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
||||
if err := gw.limit(ctx, basicRateLimitTokens); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -285,7 +277,7 @@ func (gw *Node) EthProtocolVersion(ctx context.Context) (ethtypes.EthUint64, err
|
||||
}
|
||||
|
||||
func (gw *Node) EthGasPrice(ctx context.Context) (ethtypes.EthBigInt, error) {
|
||||
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
||||
if err := gw.limit(ctx, chainRateLimitTokens); err != nil {
|
||||
return ethtypes.EthBigInt(big.Zero()), err
|
||||
}
|
||||
|
||||
@@ -304,7 +296,7 @@ func (gw *Node) EthFeeHistory(ctx context.Context, p jsonrpc.RawParams) (ethtype
|
||||
return ethtypes.EthFeeHistory{}, err
|
||||
}
|
||||
|
||||
if err := gw.checkBlkParam(ctx, params.NewestBlkNum); err != nil {
|
||||
if err := gw.checkBlkParam(ctx, params.NewestBlkNum, params.BlkCount); err != nil {
|
||||
return ethtypes.EthFeeHistory{}, err
|
||||
}
|
||||
|
||||
@@ -316,7 +308,7 @@ func (gw *Node) EthFeeHistory(ctx context.Context, p jsonrpc.RawParams) (ethtype
|
||||
}
|
||||
|
||||
func (gw *Node) EthMaxPriorityFeePerGas(ctx context.Context) (ethtypes.EthBigInt, error) {
|
||||
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
||||
if err := gw.limit(ctx, chainRateLimitTokens); err != nil {
|
||||
return ethtypes.EthBigInt(big.Zero()), err
|
||||
}
|
||||
|
||||
@@ -337,7 +329,7 @@ func (gw *Node) EthCall(ctx context.Context, tx ethtypes.EthCall, blkParam strin
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := gw.checkBlkParam(ctx, blkParam); err != nil {
|
||||
if err := gw.checkBlkParam(ctx, blkParam, 0); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -359,12 +351,12 @@ func (gw *Node) EthGetLogs(ctx context.Context, filter *ethtypes.EthFilterSpec)
|
||||
}
|
||||
|
||||
if filter.FromBlock != nil {
|
||||
if err := gw.checkBlkParam(ctx, *filter.FromBlock); err != nil {
|
||||
if err := gw.checkBlkParam(ctx, *filter.FromBlock, 0); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if filter.ToBlock != nil {
|
||||
if err := gw.checkBlkParam(ctx, *filter.ToBlock); err != nil {
|
||||
if err := gw.checkBlkParam(ctx, *filter.ToBlock, 0); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
+10
-3
@@ -247,9 +247,6 @@ func (gw *Node) MsigGetVested(ctx context.Context, addr address.Address, start t
|
||||
if err := gw.limit(ctx, walletRateLimitTokens); err != nil {
|
||||
return types.BigInt{}, err
|
||||
}
|
||||
if err := gw.checkTipsetKey(ctx, start); err != nil {
|
||||
return types.NewInt(0), err
|
||||
}
|
||||
if err := gw.checkTipsetKey(ctx, end); err != nil {
|
||||
return types.NewInt(0), err
|
||||
}
|
||||
@@ -522,6 +519,16 @@ func (gw *Node) StateVerifiedClientStatus(ctx context.Context, addr address.Addr
|
||||
return gw.target.StateVerifiedClientStatus(ctx, addr, tsk)
|
||||
}
|
||||
|
||||
func (gw *Node) StateVerifierStatus(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*abi.StoragePower, error) {
|
||||
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := gw.checkTipsetKey(ctx, tsk); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return gw.target.StateVerifierStatus(ctx, addr, tsk)
|
||||
}
|
||||
|
||||
func (gw *Node) StateVMCirculatingSupplyInternal(ctx context.Context, tsk types.TipSetKey) (api.CirculatingSupply, error) {
|
||||
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
||||
return api.CirculatingSupply{}, err
|
||||
|
||||
Reference in new issue
Block a user