2021-05-19 11:22:07 +00:00
|
|
|
package gateway
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
2022-06-07 03:14:16 +00:00
|
|
|
blocks "github.com/ipfs/go-block-format"
|
2021-08-31 11:26:46 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
2022-04-21 02:48:41 +00:00
|
|
|
"go.opencensus.io/stats"
|
2022-04-20 01:35:19 +00:00
|
|
|
"golang.org/x/time/rate"
|
2021-08-31 11:26:46 +00:00
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
2021-05-19 11:22:07 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
|
|
|
"github.com/filecoin-project/go-bitfield"
|
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
|
|
|
"github.com/filecoin-project/go-state-types/crypto"
|
|
|
|
"github.com/filecoin-project/go-state-types/dline"
|
|
|
|
"github.com/filecoin-project/go-state-types/network"
|
2022-06-14 15:00:51 +00:00
|
|
|
|
2021-05-19 11:22:07 +00:00
|
|
|
"github.com/filecoin-project/lotus/api"
|
2022-05-27 11:35:23 +00:00
|
|
|
apitypes "github.com/filecoin-project/lotus/api/types"
|
2021-05-19 11:22:07 +00:00
|
|
|
"github.com/filecoin-project/lotus/build"
|
|
|
|
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
"github.com/filecoin-project/lotus/lib/sigs"
|
|
|
|
_ "github.com/filecoin-project/lotus/lib/sigs/bls"
|
2023-01-13 19:11:13 +00:00
|
|
|
_ "github.com/filecoin-project/lotus/lib/sigs/delegated"
|
2021-05-19 11:22:07 +00:00
|
|
|
_ "github.com/filecoin-project/lotus/lib/sigs/secp"
|
2022-04-21 02:48:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/metrics"
|
2021-05-19 11:22:07 +00:00
|
|
|
"github.com/filecoin-project/lotus/node/impl/full"
|
|
|
|
)
|
|
|
|
|
2021-05-19 16:30:06 +00:00
|
|
|
const (
|
|
|
|
DefaultLookbackCap = time.Hour * 24
|
|
|
|
DefaultStateWaitLookbackLimit = abi.ChainEpoch(20)
|
2022-06-01 07:59:13 +00:00
|
|
|
DefaultRateLimitTimeout = time.Second * 5
|
2022-04-20 01:35:19 +00:00
|
|
|
basicRateLimitTokens = 1
|
|
|
|
walletRateLimitTokens = 1
|
|
|
|
chainRateLimitTokens = 2
|
|
|
|
stateRateLimitTokens = 3
|
2021-05-19 16:30:06 +00:00
|
|
|
)
|
|
|
|
|
2021-05-19 11:22:07 +00:00
|
|
|
// TargetAPI defines the API methods that the Node depends on
|
|
|
|
// (to make it easy to mock for tests)
|
|
|
|
type TargetAPI interface {
|
|
|
|
Version(context.Context) (api.APIVersion, error)
|
2021-11-18 21:55:33 +00:00
|
|
|
ChainGetParentMessages(context.Context, cid.Cid) ([]api.Message, error)
|
|
|
|
ChainGetParentReceipts(context.Context, cid.Cid) ([]*types.MessageReceipt, error)
|
2021-05-19 11:22:07 +00:00
|
|
|
ChainGetBlockMessages(context.Context, cid.Cid) (*api.BlockMessages, error)
|
|
|
|
ChainGetMessage(ctx context.Context, mc cid.Cid) (*types.Message, error)
|
|
|
|
ChainGetNode(ctx context.Context, p string) (*api.IpldObject, error)
|
|
|
|
ChainGetTipSet(ctx context.Context, tsk types.TipSetKey) (*types.TipSet, error)
|
|
|
|
ChainGetTipSetByHeight(ctx context.Context, h abi.ChainEpoch, tsk types.TipSetKey) (*types.TipSet, error)
|
2021-08-05 17:53:12 +00:00
|
|
|
ChainGetTipSetAfterHeight(ctx context.Context, h abi.ChainEpoch, tsk types.TipSetKey) (*types.TipSet, error)
|
2021-05-19 11:22:07 +00:00
|
|
|
ChainHasObj(context.Context, cid.Cid) (bool, error)
|
|
|
|
ChainHead(ctx context.Context) (*types.TipSet, error)
|
|
|
|
ChainNotify(context.Context) (<-chan []*api.HeadChange, error)
|
2021-08-27 19:25:43 +00:00
|
|
|
ChainGetPath(ctx context.Context, from, to types.TipSetKey) ([]*api.HeadChange, error)
|
2021-05-19 11:22:07 +00:00
|
|
|
ChainReadObj(context.Context, cid.Cid) ([]byte, error)
|
2022-06-07 03:14:16 +00:00
|
|
|
ChainPutObj(context.Context, blocks.Block) error
|
2021-11-18 21:55:33 +00:00
|
|
|
ChainGetGenesis(context.Context) (*types.TipSet, error)
|
2021-05-19 11:22:07 +00:00
|
|
|
GasEstimateMessageGas(ctx context.Context, msg *types.Message, spec *api.MessageSendSpec, tsk types.TipSetKey) (*types.Message, error)
|
|
|
|
MpoolPushUntrusted(ctx context.Context, sm *types.SignedMessage) (cid.Cid, error)
|
|
|
|
MsigGetAvailableBalance(ctx context.Context, addr address.Address, tsk types.TipSetKey) (types.BigInt, error)
|
|
|
|
MsigGetVested(ctx context.Context, addr address.Address, start types.TipSetKey, end types.TipSetKey) (types.BigInt, error)
|
2022-02-16 07:30:07 +00:00
|
|
|
MsigGetVestingSchedule(context.Context, address.Address, types.TipSetKey) (api.MsigVesting, error)
|
2021-05-19 11:22:07 +00:00
|
|
|
MsigGetPending(ctx context.Context, addr address.Address, ts types.TipSetKey) ([]*api.MsigTransaction, error)
|
|
|
|
StateAccountKey(ctx context.Context, addr address.Address, tsk types.TipSetKey) (address.Address, error)
|
|
|
|
StateDealProviderCollateralBounds(ctx context.Context, size abi.PaddedPieceSize, verified bool, tsk types.TipSetKey) (api.DealCollateralBounds, error)
|
|
|
|
StateGetActor(ctx context.Context, actor address.Address, ts types.TipSetKey) (*types.Actor, error)
|
|
|
|
StateLookupID(ctx context.Context, addr address.Address, tsk types.TipSetKey) (address.Address, error)
|
|
|
|
StateListMiners(ctx context.Context, tsk types.TipSetKey) ([]address.Address, error)
|
|
|
|
StateMarketBalance(ctx context.Context, addr address.Address, tsk types.TipSetKey) (api.MarketBalance, error)
|
|
|
|
StateMarketStorageDeal(ctx context.Context, dealId abi.DealID, tsk types.TipSetKey) (*api.MarketDeal, error)
|
|
|
|
StateNetworkVersion(context.Context, types.TipSetKey) (network.Version, error)
|
|
|
|
StateSearchMsg(ctx context.Context, from types.TipSetKey, msg cid.Cid, limit abi.ChainEpoch, allowReplaced bool) (*api.MsgLookup, error)
|
|
|
|
StateWaitMsg(ctx context.Context, cid cid.Cid, confidence uint64, limit abi.ChainEpoch, allowReplaced bool) (*api.MsgLookup, error)
|
|
|
|
StateReadState(ctx context.Context, actor address.Address, tsk types.TipSetKey) (*api.ActorState, error)
|
|
|
|
StateMinerPower(context.Context, address.Address, types.TipSetKey) (*api.MinerPower, error)
|
|
|
|
StateMinerFaults(context.Context, address.Address, types.TipSetKey) (bitfield.BitField, error)
|
|
|
|
StateMinerRecoveries(context.Context, address.Address, types.TipSetKey) (bitfield.BitField, error)
|
2022-04-20 21:34:28 +00:00
|
|
|
StateMinerInfo(context.Context, address.Address, types.TipSetKey) (api.MinerInfo, error)
|
2021-05-19 11:22:07 +00:00
|
|
|
StateMinerDeadlines(context.Context, address.Address, types.TipSetKey) ([]api.Deadline, error)
|
|
|
|
StateMinerAvailableBalance(context.Context, address.Address, types.TipSetKey) (types.BigInt, error)
|
|
|
|
StateMinerProvingDeadline(context.Context, address.Address, types.TipSetKey) (*dline.Info, error)
|
|
|
|
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)
|
|
|
|
StateVMCirculatingSupplyInternal(context.Context, types.TipSetKey) (api.CirculatingSupply, error)
|
|
|
|
WalletBalance(context.Context, address.Address) (types.BigInt, error) //perm:read
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ TargetAPI = *new(api.FullNode) // gateway depends on latest
|
|
|
|
|
|
|
|
type Node struct {
|
|
|
|
target TargetAPI
|
|
|
|
lookbackCap time.Duration
|
|
|
|
stateWaitLookbackLimit abi.ChainEpoch
|
2022-04-20 01:35:19 +00:00
|
|
|
rateLimiter *rate.Limiter
|
|
|
|
rateLimitTimeout time.Duration
|
2021-05-19 11:22:07 +00:00
|
|
|
errLookback error
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
_ api.Gateway = (*Node)(nil)
|
|
|
|
_ full.ChainModuleAPI = (*Node)(nil)
|
|
|
|
_ full.GasModuleAPI = (*Node)(nil)
|
|
|
|
_ full.MpoolModuleAPI = (*Node)(nil)
|
|
|
|
_ full.StateModuleAPI = (*Node)(nil)
|
|
|
|
)
|
|
|
|
|
|
|
|
// NewNode creates a new gateway node.
|
2022-04-20 01:35:19 +00:00
|
|
|
func NewNode(api TargetAPI, lookbackCap time.Duration, stateWaitLookbackLimit abi.ChainEpoch, rateLimit int64, rateLimitTimeout time.Duration) *Node {
|
|
|
|
var limit rate.Limit
|
|
|
|
if rateLimit == 0 {
|
|
|
|
limit = rate.Inf
|
|
|
|
} else {
|
|
|
|
limit = rate.Every(time.Second / time.Duration(rateLimit))
|
|
|
|
}
|
2021-05-19 11:22:07 +00:00
|
|
|
return &Node{
|
|
|
|
target: api,
|
|
|
|
lookbackCap: lookbackCap,
|
|
|
|
stateWaitLookbackLimit: stateWaitLookbackLimit,
|
2022-04-20 01:35:19 +00:00
|
|
|
rateLimiter: rate.NewLimiter(limit, stateRateLimitTokens),
|
|
|
|
rateLimitTimeout: rateLimitTimeout,
|
2021-05-19 11:22:07 +00:00
|
|
|
errLookback: fmt.Errorf("lookbacks of more than %s are disallowed", lookbackCap),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) checkTipsetKey(ctx context.Context, tsk types.TipSetKey) error {
|
|
|
|
if tsk.IsEmpty() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
ts, err := gw.target.ChainGetTipSet(ctx, tsk)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return gw.checkTipset(ts)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) checkTipset(ts *types.TipSet) error {
|
|
|
|
at := time.Unix(int64(ts.Blocks()[0].Timestamp), 0)
|
|
|
|
if err := gw.checkTimestamp(at); err != nil {
|
|
|
|
return fmt.Errorf("bad tipset: %w", err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) checkTipsetHeight(ts *types.TipSet, h abi.ChainEpoch) error {
|
|
|
|
tsBlock := ts.Blocks()[0]
|
|
|
|
heightDelta := time.Duration(uint64(tsBlock.Height-h)*build.BlockDelaySecs) * time.Second
|
|
|
|
timeAtHeight := time.Unix(int64(tsBlock.Timestamp), 0).Add(-heightDelta)
|
|
|
|
|
|
|
|
if err := gw.checkTimestamp(timeAtHeight); err != nil {
|
|
|
|
return fmt.Errorf("bad tipset height: %w", err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) checkTimestamp(at time.Time) error {
|
|
|
|
if time.Since(at) > gw.lookbackCap {
|
|
|
|
return gw.errLookback
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-04-20 01:35:19 +00:00
|
|
|
func (gw *Node) limit(ctx context.Context, tokens int) error {
|
|
|
|
ctx2, cancel := context.WithTimeout(ctx, gw.rateLimitTimeout)
|
|
|
|
defer cancel()
|
2022-06-06 23:37:11 +00:00
|
|
|
if perConnLimiter, ok := ctx2.Value(perConnLimiterKey).(*rate.Limiter); ok {
|
2022-05-20 10:40:52 +00:00
|
|
|
err := perConnLimiter.WaitN(ctx2, tokens)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("connection limited. %w", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-20 01:35:19 +00:00
|
|
|
err := gw.rateLimiter.WaitN(ctx2, tokens)
|
|
|
|
if err != nil {
|
2022-04-21 02:48:41 +00:00
|
|
|
stats.Record(ctx, metrics.RateLimitCount.M(1))
|
|
|
|
return fmt.Errorf("server busy. %w", err)
|
2022-04-20 01:35:19 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-05-27 11:35:23 +00:00
|
|
|
func (gw *Node) Discover(ctx context.Context) (apitypes.OpenRPCDocument, error) {
|
|
|
|
return build.OpenRPCDiscoverJSON_Gateway(), nil
|
|
|
|
}
|
|
|
|
|
2021-05-19 11:22:07 +00:00
|
|
|
func (gw *Node) Version(ctx context.Context) (api.APIVersion, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, basicRateLimitTokens); err != nil {
|
|
|
|
return api.APIVersion{}, err
|
|
|
|
}
|
2021-05-19 11:22:07 +00:00
|
|
|
return gw.target.Version(ctx)
|
|
|
|
}
|
|
|
|
|
2021-11-18 21:55:33 +00:00
|
|
|
func (gw *Node) ChainGetParentMessages(ctx context.Context, c cid.Cid) ([]api.Message, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, chainRateLimitTokens); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-11-18 21:55:33 +00:00
|
|
|
return gw.target.ChainGetParentMessages(ctx, c)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) ChainGetParentReceipts(ctx context.Context, c cid.Cid) ([]*types.MessageReceipt, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, chainRateLimitTokens); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-11-18 21:55:33 +00:00
|
|
|
return gw.target.ChainGetParentReceipts(ctx, c)
|
|
|
|
}
|
|
|
|
|
2021-05-19 11:22:07 +00:00
|
|
|
func (gw *Node) ChainGetBlockMessages(ctx context.Context, c cid.Cid) (*api.BlockMessages, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, chainRateLimitTokens); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-05-19 11:22:07 +00:00
|
|
|
return gw.target.ChainGetBlockMessages(ctx, c)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) ChainHasObj(ctx context.Context, c cid.Cid) (bool, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, chainRateLimitTokens); err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
2021-05-19 11:22:07 +00:00
|
|
|
return gw.target.ChainHasObj(ctx, c)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) ChainHead(ctx context.Context) (*types.TipSet, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, chainRateLimitTokens); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-05-20 10:40:52 +00:00
|
|
|
|
2021-05-19 11:22:07 +00:00
|
|
|
return gw.target.ChainHead(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) ChainGetMessage(ctx context.Context, mc cid.Cid) (*types.Message, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, chainRateLimitTokens); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-05-19 11:22:07 +00:00
|
|
|
return gw.target.ChainGetMessage(ctx, mc)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) ChainGetTipSet(ctx context.Context, tsk types.TipSetKey) (*types.TipSet, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, chainRateLimitTokens); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-05-19 11:22:07 +00:00
|
|
|
return gw.target.ChainGetTipSet(ctx, tsk)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) ChainGetTipSetByHeight(ctx context.Context, h abi.ChainEpoch, tsk types.TipSetKey) (*types.TipSet, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, chainRateLimitTokens); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-08-05 17:53:12 +00:00
|
|
|
if err := gw.checkTipSetHeight(ctx, h, tsk); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return gw.target.ChainGetTipSetByHeight(ctx, h, tsk)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) ChainGetTipSetAfterHeight(ctx context.Context, h abi.ChainEpoch, tsk types.TipSetKey) (*types.TipSet, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, chainRateLimitTokens); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-08-05 17:53:12 +00:00
|
|
|
if err := gw.checkTipSetHeight(ctx, h, tsk); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return gw.target.ChainGetTipSetAfterHeight(ctx, h, tsk)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) checkTipSetHeight(ctx context.Context, h abi.ChainEpoch, tsk types.TipSetKey) error {
|
2021-05-19 11:22:07 +00:00
|
|
|
var ts *types.TipSet
|
|
|
|
if tsk.IsEmpty() {
|
|
|
|
head, err := gw.target.ChainHead(ctx)
|
|
|
|
if err != nil {
|
2021-08-05 17:53:12 +00:00
|
|
|
return err
|
2021-05-19 11:22:07 +00:00
|
|
|
}
|
|
|
|
ts = head
|
|
|
|
} else {
|
|
|
|
gts, err := gw.target.ChainGetTipSet(ctx, tsk)
|
|
|
|
if err != nil {
|
2021-08-05 17:53:12 +00:00
|
|
|
return err
|
2021-05-19 11:22:07 +00:00
|
|
|
}
|
|
|
|
ts = gts
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the tipset key refers to gw tipset that's too far in the past
|
|
|
|
if err := gw.checkTipset(ts); err != nil {
|
2021-08-05 17:53:12 +00:00
|
|
|
return err
|
2021-05-19 11:22:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the height is too far in the past
|
|
|
|
if err := gw.checkTipsetHeight(ts, h); err != nil {
|
2021-08-05 17:53:12 +00:00
|
|
|
return err
|
2021-05-19 11:22:07 +00:00
|
|
|
}
|
|
|
|
|
2021-08-05 17:53:12 +00:00
|
|
|
return nil
|
2021-05-19 11:22:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) ChainGetNode(ctx context.Context, p string) (*api.IpldObject, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, chainRateLimitTokens); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-05-19 11:22:07 +00:00
|
|
|
return gw.target.ChainGetNode(ctx, p)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) ChainNotify(ctx context.Context) (<-chan []*api.HeadChange, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, chainRateLimitTokens); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-05-19 11:22:07 +00:00
|
|
|
return gw.target.ChainNotify(ctx)
|
|
|
|
}
|
|
|
|
|
2021-08-27 19:25:43 +00:00
|
|
|
func (gw *Node) ChainGetPath(ctx context.Context, from, to types.TipSetKey) ([]*api.HeadChange, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, chainRateLimitTokens); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-08-31 10:51:13 +00:00
|
|
|
if err := gw.checkTipsetKey(ctx, from); err != nil {
|
|
|
|
return nil, xerrors.Errorf("gateway: checking 'from' tipset: %w", err)
|
|
|
|
}
|
|
|
|
if err := gw.checkTipsetKey(ctx, to); err != nil {
|
|
|
|
return nil, xerrors.Errorf("gateway: checking 'to' tipset: %w", err)
|
|
|
|
}
|
2021-08-27 19:25:43 +00:00
|
|
|
return gw.target.ChainGetPath(ctx, from, to)
|
|
|
|
}
|
|
|
|
|
2021-11-18 21:55:33 +00:00
|
|
|
func (gw *Node) ChainGetGenesis(ctx context.Context) (*types.TipSet, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, chainRateLimitTokens); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-11-18 21:55:33 +00:00
|
|
|
return gw.target.ChainGetGenesis(ctx)
|
|
|
|
}
|
|
|
|
|
2021-05-19 11:22:07 +00:00
|
|
|
func (gw *Node) ChainReadObj(ctx context.Context, c cid.Cid) ([]byte, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, chainRateLimitTokens); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-05-19 11:22:07 +00:00
|
|
|
return gw.target.ChainReadObj(ctx, c)
|
|
|
|
}
|
|
|
|
|
2022-06-07 03:14:16 +00:00
|
|
|
func (gw *Node) ChainPutObj(context.Context, blocks.Block) error {
|
|
|
|
return xerrors.New("not supported")
|
|
|
|
}
|
|
|
|
|
2021-05-19 11:22:07 +00:00
|
|
|
func (gw *Node) GasEstimateMessageGas(ctx context.Context, msg *types.Message, spec *api.MessageSendSpec, tsk types.TipSetKey) (*types.Message, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-05-19 11:22:07 +00:00
|
|
|
if err := gw.checkTipsetKey(ctx, tsk); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return gw.target.GasEstimateMessageGas(ctx, msg, spec, tsk)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) MpoolPush(ctx context.Context, sm *types.SignedMessage) (cid.Cid, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
|
|
|
return cid.Cid{}, err
|
|
|
|
}
|
2021-05-19 11:22:07 +00:00
|
|
|
// TODO: additional anti-spam checks
|
|
|
|
return gw.target.MpoolPushUntrusted(ctx, sm)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) MsigGetAvailableBalance(ctx context.Context, addr address.Address, tsk types.TipSetKey) (types.BigInt, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, walletRateLimitTokens); err != nil {
|
|
|
|
return types.BigInt{}, err
|
|
|
|
}
|
2021-05-19 11:22:07 +00:00
|
|
|
if err := gw.checkTipsetKey(ctx, tsk); err != nil {
|
|
|
|
return types.NewInt(0), err
|
|
|
|
}
|
|
|
|
return gw.target.MsigGetAvailableBalance(ctx, addr, tsk)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) MsigGetVested(ctx context.Context, addr address.Address, start types.TipSetKey, end types.TipSetKey) (types.BigInt, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, walletRateLimitTokens); err != nil {
|
|
|
|
return types.BigInt{}, err
|
|
|
|
}
|
2021-05-19 11:22:07 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
return gw.target.MsigGetVested(ctx, addr, start, end)
|
|
|
|
}
|
|
|
|
|
2022-02-16 07:30:07 +00:00
|
|
|
func (gw *Node) MsigGetVestingSchedule(ctx context.Context, addr address.Address, tsk types.TipSetKey) (api.MsigVesting, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, walletRateLimitTokens); err != nil {
|
|
|
|
return api.MsigVesting{}, err
|
|
|
|
}
|
2022-02-16 07:30:07 +00:00
|
|
|
if err := gw.checkTipsetKey(ctx, tsk); err != nil {
|
|
|
|
return api.MsigVesting{}, err
|
|
|
|
}
|
|
|
|
return gw.target.MsigGetVestingSchedule(ctx, addr, tsk)
|
|
|
|
}
|
|
|
|
|
2021-05-19 11:22:07 +00:00
|
|
|
func (gw *Node) MsigGetPending(ctx context.Context, addr address.Address, tsk types.TipSetKey) ([]*api.MsigTransaction, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, walletRateLimitTokens); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-05-19 11:22:07 +00:00
|
|
|
if err := gw.checkTipsetKey(ctx, tsk); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return gw.target.MsigGetPending(ctx, addr, tsk)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) StateAccountKey(ctx context.Context, addr address.Address, tsk types.TipSetKey) (address.Address, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
|
|
|
return address.Address{}, err
|
|
|
|
}
|
2021-05-19 11:22:07 +00:00
|
|
|
if err := gw.checkTipsetKey(ctx, tsk); err != nil {
|
|
|
|
return address.Undef, err
|
|
|
|
}
|
|
|
|
return gw.target.StateAccountKey(ctx, addr, tsk)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) StateDealProviderCollateralBounds(ctx context.Context, size abi.PaddedPieceSize, verified bool, tsk types.TipSetKey) (api.DealCollateralBounds, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
|
|
|
return api.DealCollateralBounds{}, err
|
|
|
|
}
|
2021-05-19 11:22:07 +00:00
|
|
|
if err := gw.checkTipsetKey(ctx, tsk); err != nil {
|
|
|
|
return api.DealCollateralBounds{}, err
|
|
|
|
}
|
|
|
|
return gw.target.StateDealProviderCollateralBounds(ctx, size, verified, tsk)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) StateGetActor(ctx context.Context, actor address.Address, tsk types.TipSetKey) (*types.Actor, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-05-19 11:22:07 +00:00
|
|
|
if err := gw.checkTipsetKey(ctx, tsk); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return gw.target.StateGetActor(ctx, actor, tsk)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) StateListMiners(ctx context.Context, tsk types.TipSetKey) ([]address.Address, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-05-19 11:22:07 +00:00
|
|
|
if err := gw.checkTipsetKey(ctx, tsk); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return gw.target.StateListMiners(ctx, tsk)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) StateLookupID(ctx context.Context, addr address.Address, tsk types.TipSetKey) (address.Address, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
|
|
|
return address.Address{}, err
|
|
|
|
}
|
2021-05-19 11:22:07 +00:00
|
|
|
if err := gw.checkTipsetKey(ctx, tsk); err != nil {
|
|
|
|
return address.Undef, err
|
|
|
|
}
|
|
|
|
return gw.target.StateLookupID(ctx, addr, tsk)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) StateMarketBalance(ctx context.Context, addr address.Address, tsk types.TipSetKey) (api.MarketBalance, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
|
|
|
return api.MarketBalance{}, err
|
|
|
|
}
|
2021-05-19 11:22:07 +00:00
|
|
|
if err := gw.checkTipsetKey(ctx, tsk); err != nil {
|
|
|
|
return api.MarketBalance{}, err
|
|
|
|
}
|
|
|
|
return gw.target.StateMarketBalance(ctx, addr, tsk)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) StateMarketStorageDeal(ctx context.Context, dealId abi.DealID, tsk types.TipSetKey) (*api.MarketDeal, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-05-19 11:22:07 +00:00
|
|
|
if err := gw.checkTipsetKey(ctx, tsk); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return gw.target.StateMarketStorageDeal(ctx, dealId, tsk)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) StateNetworkVersion(ctx context.Context, tsk types.TipSetKey) (network.Version, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
|
|
|
return network.VersionMax, err
|
|
|
|
}
|
2021-05-19 11:22:07 +00:00
|
|
|
if err := gw.checkTipsetKey(ctx, tsk); err != nil {
|
|
|
|
return network.VersionMax, err
|
|
|
|
}
|
|
|
|
return gw.target.StateNetworkVersion(ctx, tsk)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) StateSearchMsg(ctx context.Context, from types.TipSetKey, msg cid.Cid, limit abi.ChainEpoch, allowReplaced bool) (*api.MsgLookup, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-05-19 11:22:07 +00:00
|
|
|
if limit == api.LookbackNoLimit {
|
|
|
|
limit = gw.stateWaitLookbackLimit
|
|
|
|
}
|
|
|
|
if gw.stateWaitLookbackLimit != api.LookbackNoLimit && limit > gw.stateWaitLookbackLimit {
|
|
|
|
limit = gw.stateWaitLookbackLimit
|
|
|
|
}
|
|
|
|
if err := gw.checkTipsetKey(ctx, from); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return gw.target.StateSearchMsg(ctx, from, msg, limit, allowReplaced)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) StateWaitMsg(ctx context.Context, msg cid.Cid, confidence uint64, limit abi.ChainEpoch, allowReplaced bool) (*api.MsgLookup, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-05-19 11:22:07 +00:00
|
|
|
if limit == api.LookbackNoLimit {
|
|
|
|
limit = gw.stateWaitLookbackLimit
|
|
|
|
}
|
|
|
|
if gw.stateWaitLookbackLimit != api.LookbackNoLimit && limit > gw.stateWaitLookbackLimit {
|
|
|
|
limit = gw.stateWaitLookbackLimit
|
|
|
|
}
|
|
|
|
return gw.target.StateWaitMsg(ctx, msg, confidence, limit, allowReplaced)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) StateReadState(ctx context.Context, actor address.Address, tsk types.TipSetKey) (*api.ActorState, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-05-19 11:22:07 +00:00
|
|
|
if err := gw.checkTipsetKey(ctx, tsk); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return gw.target.StateReadState(ctx, actor, tsk)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) StateMinerPower(ctx context.Context, m address.Address, tsk types.TipSetKey) (*api.MinerPower, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-05-19 11:22:07 +00:00
|
|
|
if err := gw.checkTipsetKey(ctx, tsk); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return gw.target.StateMinerPower(ctx, m, tsk)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) StateMinerFaults(ctx context.Context, m address.Address, tsk types.TipSetKey) (bitfield.BitField, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
|
|
|
return bitfield.BitField{}, err
|
|
|
|
}
|
2021-05-19 11:22:07 +00:00
|
|
|
if err := gw.checkTipsetKey(ctx, tsk); err != nil {
|
|
|
|
return bitfield.BitField{}, err
|
|
|
|
}
|
|
|
|
return gw.target.StateMinerFaults(ctx, m, tsk)
|
|
|
|
}
|
2022-04-20 01:35:19 +00:00
|
|
|
|
2021-05-19 11:22:07 +00:00
|
|
|
func (gw *Node) StateMinerRecoveries(ctx context.Context, m address.Address, tsk types.TipSetKey) (bitfield.BitField, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
|
|
|
return bitfield.BitField{}, err
|
|
|
|
}
|
2021-05-19 11:22:07 +00:00
|
|
|
if err := gw.checkTipsetKey(ctx, tsk); err != nil {
|
|
|
|
return bitfield.BitField{}, err
|
|
|
|
}
|
|
|
|
return gw.target.StateMinerRecoveries(ctx, m, tsk)
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
func (gw *Node) StateMinerInfo(ctx context.Context, m address.Address, tsk types.TipSetKey) (api.MinerInfo, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
2022-06-10 11:01:20 +00:00
|
|
|
return api.MinerInfo{}, err
|
2022-04-20 01:35:19 +00:00
|
|
|
}
|
2021-05-19 11:22:07 +00:00
|
|
|
if err := gw.checkTipsetKey(ctx, tsk); err != nil {
|
2022-04-20 21:34:28 +00:00
|
|
|
return api.MinerInfo{}, err
|
2021-05-19 11:22:07 +00:00
|
|
|
}
|
|
|
|
return gw.target.StateMinerInfo(ctx, m, tsk)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) StateMinerDeadlines(ctx context.Context, m address.Address, tsk types.TipSetKey) ([]api.Deadline, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-05-19 11:22:07 +00:00
|
|
|
if err := gw.checkTipsetKey(ctx, tsk); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return gw.target.StateMinerDeadlines(ctx, m, tsk)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) StateMinerAvailableBalance(ctx context.Context, m address.Address, tsk types.TipSetKey) (types.BigInt, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
|
|
|
return types.BigInt{}, err
|
|
|
|
}
|
2021-05-19 11:22:07 +00:00
|
|
|
if err := gw.checkTipsetKey(ctx, tsk); err != nil {
|
|
|
|
return types.BigInt{}, err
|
|
|
|
}
|
|
|
|
return gw.target.StateMinerAvailableBalance(ctx, m, tsk)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) StateMinerProvingDeadline(ctx context.Context, m address.Address, tsk types.TipSetKey) (*dline.Info, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-05-19 11:22:07 +00:00
|
|
|
if err := gw.checkTipsetKey(ctx, tsk); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return gw.target.StateMinerProvingDeadline(ctx, m, tsk)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) StateCirculatingSupply(ctx context.Context, tsk types.TipSetKey) (abi.TokenAmount, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
|
|
|
return abi.TokenAmount{}, err
|
|
|
|
}
|
2021-05-19 11:22:07 +00:00
|
|
|
if err := gw.checkTipsetKey(ctx, tsk); err != nil {
|
2022-04-20 01:35:19 +00:00
|
|
|
return abi.TokenAmount{}, err
|
2021-05-19 11:22:07 +00:00
|
|
|
}
|
|
|
|
return gw.target.StateCirculatingSupply(ctx, tsk)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) StateSectorGetInfo(ctx context.Context, maddr address.Address, n abi.SectorNumber, tsk types.TipSetKey) (*miner.SectorOnChainInfo, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-05-19 11:22:07 +00:00
|
|
|
if err := gw.checkTipsetKey(ctx, tsk); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return gw.target.StateSectorGetInfo(ctx, maddr, n, tsk)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) StateVerifiedClientStatus(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*abi.StoragePower, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-05-19 11:22:07 +00:00
|
|
|
if err := gw.checkTipsetKey(ctx, tsk); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return gw.target.StateVerifiedClientStatus(ctx, addr, tsk)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) StateVMCirculatingSupplyInternal(ctx context.Context, tsk types.TipSetKey) (api.CirculatingSupply, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
|
|
|
return api.CirculatingSupply{}, err
|
|
|
|
}
|
2021-05-19 11:22:07 +00:00
|
|
|
if err := gw.checkTipsetKey(ctx, tsk); err != nil {
|
|
|
|
return api.CirculatingSupply{}, err
|
|
|
|
}
|
|
|
|
return gw.target.StateVMCirculatingSupplyInternal(ctx, tsk)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) WalletVerify(ctx context.Context, k address.Address, msg []byte, sig *crypto.Signature) (bool, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
2021-05-19 11:22:07 +00:00
|
|
|
return sigs.Verify(sig, k, msg) == nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gw *Node) WalletBalance(ctx context.Context, k address.Address) (types.BigInt, error) {
|
2022-04-20 01:35:19 +00:00
|
|
|
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
|
|
|
|
return types.BigInt{}, err
|
|
|
|
}
|
2021-05-19 11:22:07 +00:00
|
|
|
return gw.target.WalletBalance(ctx, k)
|
|
|
|
}
|