diff --git a/api/client/client.go b/api/client/client.go index 1b49aae78..0165bcbd8 100644 --- a/api/client/client.go +++ b/api/client/client.go @@ -96,8 +96,8 @@ func NewWorkerRPCV0(ctx context.Context, addr string, requestHeader http.Header) return &res, closer, err } -// NewGatewayRPCV0 creates a new http jsonrpc client for a gateway node. -func NewGatewayRPCV0(ctx context.Context, addr string, requestHeader http.Header, opts ...jsonrpc.Option) (api.Gateway, jsonrpc.ClientCloser, error) { +// NewGatewayRPCV1 creates a new http jsonrpc client for a gateway node. +func NewGatewayRPCV1(ctx context.Context, addr string, requestHeader http.Header, opts ...jsonrpc.Option) (api.Gateway, jsonrpc.ClientCloser, error) { var res api.GatewayStruct closer, err := jsonrpc.NewMergeClient(ctx, addr, "Filecoin", []interface{}{ diff --git a/api/test/paych.go b/api/test/paych.go index b38ba6189..93a083c4a 100644 --- a/api/test/paych.go +++ b/api/test/paych.go @@ -235,7 +235,7 @@ func TestPaymentChannels(t *testing.T, b APIBuilder, blocktime time.Duration) { if err != nil { t.Fatal(err) } - res, err = paymentReceiver.StateWaitMsg(ctx, collectMsg, 3) + res, err = paymentReceiver.StateWaitMsg(ctx, collectMsg, 3, api.LookbackNoLimit, true) if err != nil { t.Fatal(err) } @@ -287,7 +287,7 @@ func waitForBlocks(ctx context.Context, t *testing.T, bm *BlockMiner, paymentRec t.Fatal(err) } - _, err = paymentReceiver.StateWaitMsg(ctx, m.Cid(), 1) + _, err = paymentReceiver.StateWaitMsg(ctx, m.Cid(), 1, api.LookbackNoLimit, true) if err != nil { t.Fatal(err) } @@ -299,7 +299,7 @@ func waitForMessage(ctx context.Context, t *testing.T, paymentCreator TestNode, defer cancel() fmt.Println("Waiting for", desc) - res, err := paymentCreator.StateWaitMsg(ctx, msgCid, 1) + res, err := paymentCreator.StateWaitMsg(ctx, msgCid, 1, api.LookbackNoLimit, true) if err != nil { fmt.Println("Error waiting for", desc, err) t.Fatal(err) diff --git a/api/test/test.go b/api/test/test.go index aaaf55b8b..e5edcbe3b 100644 --- a/api/test/test.go +++ b/api/test/test.go @@ -21,7 +21,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/network" - "github.com/filecoin-project/lotus/api" + lapi "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/miner" "github.com/filecoin-project/lotus/node" @@ -44,7 +44,7 @@ type TestNode struct { } type TestStorageNode struct { - api.StorageMiner + lapi.StorageMiner // ListenAddr is the address on which an API server is listening, if an // API server is created for this Node ListenAddr multiaddr.Multiaddr @@ -156,7 +156,7 @@ var MineNext = miner.MineReq{ } func (ts *testSuite) testVersion(t *testing.T) { - api.RunningNodeType = api.NodeFull + lapi.RunningNodeType = lapi.NodeFull ctx := context.Background() apis, _ := ts.makeNodes(t, OneFull, OneMiner) @@ -197,7 +197,7 @@ func (ts *testSuite) testSearchMsg(t *testing.T) { if err != nil { t.Fatal(err) } - res, err := api.StateWaitMsg(ctx, sm.Cid(), 1) + res, err := api.StateWaitMsg(ctx, sm.Cid(), 1, lapi.LookbackNoLimit, true) if err != nil { t.Fatal(err) } @@ -205,7 +205,7 @@ func (ts *testSuite) testSearchMsg(t *testing.T) { t.Fatal("did not successfully send message") } - searchRes, err := api.StateSearchMsg(ctx, sm.Cid()) + searchRes, err := api.StateSearchMsg(ctx, types.EmptyTSK, sm.Cid(), lapi.LookbackNoLimit, true) if err != nil { t.Fatal(err) } diff --git a/api/test/util.go b/api/test/util.go index 8695e2e2e..f571b48da 100644 --- a/api/test/util.go +++ b/api/test/util.go @@ -8,6 +8,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-address" + lapi "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/miner" ) @@ -28,7 +29,7 @@ func SendFunds(ctx context.Context, t *testing.T, sender TestNode, addr address. if err != nil { t.Fatal(err) } - res, err := sender.StateWaitMsg(ctx, sm.Cid(), 1) + res, err := sender.StateWaitMsg(ctx, sm.Cid(), 1, lapi.LookbackNoLimit, true) if err != nil { t.Fatal(err) } diff --git a/api/test/window_post.go b/api/test/window_post.go index ce42318b2..fec7e0d73 100644 --- a/api/test/window_post.go +++ b/api/test/window_post.go @@ -766,7 +766,7 @@ func TestWindowPostDispute(t *testing.T, b APIBuilder, blocktime time.Duration) require.NoError(t, err) fmt.Println("waiting dispute") - rec, err := client.StateWaitMsg(ctx, sm.Cid(), build.MessageConfidence) + rec, err := client.StateWaitMsg(ctx, sm.Cid(), build.MessageConfidence, api.LookbackNoLimit, true) require.NoError(t, err) require.Zero(t, rec.Receipt.ExitCode, "dispute not accepted: %s", rec.Receipt.ExitCode.Error()) } @@ -807,7 +807,7 @@ func TestWindowPostDispute(t *testing.T, b APIBuilder, blocktime time.Duration) sm, err := client.MpoolPushMessage(ctx, msg, nil) require.NoError(t, err) - rec, err := client.StateWaitMsg(ctx, sm.Cid(), build.MessageConfidence) + rec, err := client.StateWaitMsg(ctx, sm.Cid(), build.MessageConfidence, api.LookbackNoLimit, true) require.NoError(t, err) require.Zero(t, rec.Receipt.ExitCode, "recovery not accepted: %s", rec.Receipt.ExitCode.Error()) } @@ -886,7 +886,7 @@ func submitBadProof( return err } - rec, err := client.StateWaitMsg(ctx, sm.Cid(), build.MessageConfidence) + rec, err := client.StateWaitMsg(ctx, sm.Cid(), build.MessageConfidence, api.LookbackNoLimit, true) if err != nil { return err } diff --git a/api/v0api/v1_wrapper.go b/api/v0api/v1_wrapper.go index 091ec2fdf..bb33fa12a 100644 --- a/api/v0api/v1_wrapper.go +++ b/api/v0api/v1_wrapper.go @@ -11,7 +11,6 @@ import ( "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api/v1api" - "github.com/filecoin-project/lotus/chain/stmgr" ) type WrapperV1Full struct { @@ -19,7 +18,7 @@ type WrapperV1Full struct { } func (w *WrapperV1Full) StateSearchMsg(ctx context.Context, msg cid.Cid) (*api.MsgLookup, error) { - return w.FullNode.StateSearchMsg(ctx, types.EmptyTSK, msg, stmgr.LookbackNoLimit, true) + return w.FullNode.StateSearchMsg(ctx, types.EmptyTSK, msg, api.LookbackNoLimit, true) } func (w *WrapperV1Full) StateSearchMsgLimited(ctx context.Context, msg cid.Cid, limit abi.ChainEpoch) (*api.MsgLookup, error) { @@ -27,7 +26,7 @@ func (w *WrapperV1Full) StateSearchMsgLimited(ctx context.Context, msg cid.Cid, } func (w *WrapperV1Full) StateWaitMsg(ctx context.Context, msg cid.Cid, confidence uint64) (*api.MsgLookup, error) { - return w.FullNode.StateWaitMsg(ctx, msg, confidence, stmgr.LookbackNoLimit, true) + return w.FullNode.StateWaitMsg(ctx, msg, confidence, api.LookbackNoLimit, true) } func (w *WrapperV1Full) StateWaitMsgLimited(ctx context.Context, msg cid.Cid, confidence uint64, limit abi.ChainEpoch) (*api.MsgLookup, error) { @@ -35,7 +34,7 @@ func (w *WrapperV1Full) StateWaitMsgLimited(ctx context.Context, msg cid.Cid, co } func (w *WrapperV1Full) StateGetReceipt(ctx context.Context, msg cid.Cid, from types.TipSetKey) (*types.MessageReceipt, error) { - ml, err := w.FullNode.StateSearchMsg(ctx, from, msg, stmgr.LookbackNoLimit, true) + ml, err := w.FullNode.StateSearchMsg(ctx, from, msg, api.LookbackNoLimit, true) if err != nil { return nil, err } diff --git a/api/wrap.go b/api/wrap.go index 09f103e0c..1ded67132 100644 --- a/api/wrap.go +++ b/api/wrap.go @@ -14,7 +14,7 @@ func Wrap(proxyT, wrapperT, impl interface{}) interface{} { for i := 0; i < ri.NumMethod(); i++ { mt := ri.Type().Method(i) - if proxyMethods.FieldByName(mt.Name).IsZero() { + if proxyMethods.FieldByName(mt.Name).Kind() == reflect.Invalid { continue } diff --git a/chain/market/fundmanager_test.go b/chain/market/fundmanager_test.go index ac6b2a405..125304343 100644 --- a/chain/market/fundmanager_test.go +++ b/chain/market/fundmanager_test.go @@ -793,7 +793,7 @@ func (mapi *mockFundManagerAPI) publish(addr address.Address, amt abi.TokenAmoun mapi.escrow[addr] = escrow } -func (mapi *mockFundManagerAPI) StateWaitMsg(ctx context.Context, c cid.Cid, confidence uint64) (*api.MsgLookup, error) { +func (mapi *mockFundManagerAPI) StateWaitMsg(ctx context.Context, c cid.Cid, confidence uint64, limit abi.ChainEpoch, allowReplaced bool) (*api.MsgLookup, error) { res := &api.MsgLookup{ Message: c, Receipt: types.MessageReceipt{ diff --git a/chain/sync_test.go b/chain/sync_test.go index 9570eda32..c7cd66a8e 100644 --- a/chain/sync_test.go +++ b/chain/sync_test.go @@ -622,17 +622,17 @@ func TestDuplicateNonce(t *testing.T) { var includedMsg cid.Cid var skippedMsg cid.Cid - r0, err0 := tu.nds[0].StateGetReceipt(context.TODO(), msgs[0][0].Cid(), ts2.TipSet().Key()) - r1, err1 := tu.nds[0].StateGetReceipt(context.TODO(), msgs[1][0].Cid(), ts2.TipSet().Key()) + r0, err0 := tu.nds[0].StateSearchMsg(context.TODO(), ts2.TipSet().Key(), msgs[0][0].Cid(), api.LookbackNoLimit, true) + r1, err1 := tu.nds[0].StateSearchMsg(context.TODO(), ts2.TipSet().Key(), msgs[1][0].Cid(), api.LookbackNoLimit, true) if err0 == nil { require.Error(t, err1, "at least one of the StateGetReceipt calls should fail") - require.True(t, r0.ExitCode.IsSuccess()) + require.True(t, r0.Receipt.ExitCode.IsSuccess()) includedMsg = msgs[0][0].Message.Cid() skippedMsg = msgs[1][0].Message.Cid() } else { require.NoError(t, err1, "both the StateGetReceipt calls should not fail") - require.True(t, r1.ExitCode.IsSuccess()) + require.True(t, r1.Receipt.ExitCode.IsSuccess()) includedMsg = msgs[1][0].Message.Cid() skippedMsg = msgs[0][0].Message.Cid() } diff --git a/cli/services_send_test.go b/cli/services_send_test.go index 9dfc3b38a..713e81b2a 100644 --- a/cli/services_send_test.go +++ b/cli/services_send_test.go @@ -9,7 +9,7 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/lotus/api" - "github.com/filecoin-project/lotus/api/mocks" + mocks "github.com/filecoin-project/lotus/api/v0api/v0mocks" types "github.com/filecoin-project/lotus/chain/types" gomock "github.com/golang/mock/gomock" cid "github.com/ipfs/go-cid" diff --git a/cli/util/api.go b/cli/util/api.go index 998d1e760..38ff5efed 100644 --- a/cli/util/api.go +++ b/cli/util/api.go @@ -177,7 +177,7 @@ func GetAPI(ctx *cli.Context) (api.Common, jsonrpc.ClientCloser, error) { func GetFullNodeAPI(ctx *cli.Context) (v0api.FullNode, jsonrpc.ClientCloser, error) { if tn, ok := ctx.App.Metadata["testnode-full"]; ok { - return tn.(v0api.FullNode), func() {}, nil + return &v0api.WrapperV1Full{FullNode: tn.(v1api.FullNode)}, func() {}, nil } addr, headers, err := GetRawAPI(ctx, repo.FullNode, "v0") @@ -260,7 +260,7 @@ func GetGatewayAPI(ctx *cli.Context) (api.Gateway, jsonrpc.ClientCloser, error) return nil, nil, err } - return client.NewGatewayRPCV0(ctx.Context, addr, headers) + return client.NewGatewayRPCV1(ctx.Context, addr, headers) } func DaemonContext(cctx *cli.Context) context.Context { diff --git a/cmd/chain-noise/main.go b/cmd/chain-noise/main.go index 37d623ce2..8106ce592 100644 --- a/cmd/chain-noise/main.go +++ b/cmd/chain-noise/main.go @@ -8,7 +8,7 @@ import ( "time" "github.com/filecoin-project/go-address" - "github.com/filecoin-project/lotus/api" + "github.com/filecoin-project/lotus/api/v0api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/types" lcli "github.com/filecoin-project/lotus/cli" @@ -72,7 +72,7 @@ var runCmd = &cli.Command{ }, } -func sendSmallFundsTxs(ctx context.Context, api api.FullNode, from address.Address, rate, limit int) error { +func sendSmallFundsTxs(ctx context.Context, api v0api.FullNode, from address.Address, rate, limit int) error { var sendSet []address.Address for i := 0; i < 20; i++ { naddr, err := api.WalletNew(ctx, types.KTSecp256k1) diff --git a/cmd/lotus-gateway/endtoend_test.go b/cmd/lotus-gateway/endtoend_test.go index f575c5776..084218b24 100644 --- a/cmd/lotus-gateway/endtoend_test.go +++ b/cmd/lotus-gateway/endtoend_test.go @@ -24,6 +24,8 @@ import ( "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api/client" "github.com/filecoin-project/lotus/api/test" + "github.com/filecoin-project/lotus/api/v0api" + "github.com/filecoin-project/lotus/api/v1api" "github.com/filecoin-project/lotus/chain/actors/policy" "github.com/filecoin-project/lotus/chain/stmgr" "github.com/filecoin-project/lotus/chain/types" @@ -103,7 +105,7 @@ func TestWalletMsig(t *testing.T) { addProposal, err := lite.MsigCreate(ctx, 2, msigAddrs, abi.ChainEpoch(50), amt, liteWalletAddr, types.NewInt(0)) require.NoError(t, err) - res, err := lite.StateWaitMsg(ctx, addProposal, 1) + res, err := lite.StateWaitMsg(ctx, addProposal, 1, api.LookbackNoLimit, true) require.NoError(t, err) require.EqualValues(t, 0, res.Receipt.ExitCode) @@ -123,7 +125,7 @@ func TestWalletMsig(t *testing.T) { addProposal, err = lite.MsigAddPropose(ctx, msig, walletAddrs[0], walletAddrs[3], false) require.NoError(t, err) - res, err = lite.StateWaitMsg(ctx, addProposal, 1) + res, err = lite.StateWaitMsg(ctx, addProposal, 1, api.LookbackNoLimit, true) require.NoError(t, err) require.EqualValues(t, 0, res.Receipt.ExitCode) @@ -137,7 +139,7 @@ func TestWalletMsig(t *testing.T) { approval1, err := lite.MsigAddApprove(ctx, msig, walletAddrs[1], txnID, walletAddrs[0], walletAddrs[3], false) require.NoError(t, err) - res, err = lite.StateWaitMsg(ctx, approval1, 1) + res, err = lite.StateWaitMsg(ctx, approval1, 1, api.LookbackNoLimit, true) require.NoError(t, err) require.EqualValues(t, 0, res.Receipt.ExitCode) @@ -245,12 +247,15 @@ func startNodes( // Create a gateway server in front of the full node gapiImpl := newGatewayAPI(fullNode, lookbackCap, stateWaitLookbackLimit) - _, addr, err := builder.CreateRPCServer(t, gapiImpl) + _, addr, err := builder.CreateRPCServer(t, map[string]interface{}{ + "/rpc/v1": gapiImpl, + "/rpc/v0": api.Wrap(new(v1api.FullNodeStruct), new(v0api.WrapperV1Full), gapiImpl), + }) require.NoError(t, err) // Create a gateway client API that connects to the gateway server var gapi api.Gateway - gapi, closer, err = client.NewGatewayRPCV0(ctx, addr, nil) + gapi, closer, err = client.NewGatewayRPCV1(ctx, addr+"/rpc/v1", nil) require.NoError(t, err) // Provide the gateway API to dependency injection @@ -299,7 +304,7 @@ func sendFunds(ctx context.Context, fromNode test.TestNode, fromAddr address.Add return err } - res, err := fromNode.StateWaitMsg(ctx, sm.Cid(), 1) + res, err := fromNode.StateWaitMsg(ctx, sm.Cid(), 1, api.LookbackNoLimit, true) if err != nil { return err } diff --git a/node/test/builder.go b/node/test/builder.go index 8a887f55d..497591cde 100644 --- a/node/test/builder.go +++ b/node/test/builder.go @@ -12,6 +12,7 @@ import ( "testing" "time" + "github.com/gorilla/mux" "golang.org/x/xerrors" "github.com/filecoin-project/go-address" @@ -22,6 +23,7 @@ import ( "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api/client" "github.com/filecoin-project/lotus/api/test" + "github.com/filecoin-project/lotus/api/v0api" "github.com/filecoin-project/lotus/api/v1api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain" @@ -501,12 +503,15 @@ func mockSbBuilderOpts(t *testing.T, fullOpts []test.FullNodeOpts, storage []tes } func fullRpc(t *testing.T, nd test.TestNode) test.TestNode { - ma, listenAddr, err := CreateRPCServer(t, nd) + ma, listenAddr, err := CreateRPCServer(t, map[string]interface{}{ + "/rpc/v1": nd, + "/rpc/v0": &v0api.WrapperV1Full{FullNode: nd}, + }) require.NoError(t, err) var stop func() var full test.TestNode - full.FullNode, stop, err = client.NewFullNodeRPCV1(context.Background(), listenAddr, nil) + full.FullNode, stop, err = client.NewFullNodeRPCV1(context.Background(), listenAddr+"/rpc/v1", nil) require.NoError(t, err) t.Cleanup(stop) @@ -515,12 +520,14 @@ func fullRpc(t *testing.T, nd test.TestNode) test.TestNode { } func storerRpc(t *testing.T, nd test.TestStorageNode) test.TestStorageNode { - ma, listenAddr, err := CreateRPCServer(t, nd) + ma, listenAddr, err := CreateRPCServer(t, map[string]interface{}{ + "/rpc/v0": nd, + }) require.NoError(t, err) var stop func() var storer test.TestStorageNode - storer.StorageMiner, stop, err = client.NewStorageMinerRPCV0(context.Background(), listenAddr, nil) + storer.StorageMiner, stop, err = client.NewStorageMinerRPCV0(context.Background(), listenAddr+"/rpc/v0", nil) require.NoError(t, err) t.Cleanup(stop) @@ -529,10 +536,14 @@ func storerRpc(t *testing.T, nd test.TestStorageNode) test.TestStorageNode { return storer } -func CreateRPCServer(t *testing.T, handler interface{}) (multiaddr.Multiaddr, string, error) { - rpcServer := jsonrpc.NewServer() - rpcServer.Register("Filecoin", handler) - testServ := httptest.NewServer(rpcServer) // todo: close +func CreateRPCServer(t *testing.T, handlers map[string]interface{}) (multiaddr.Multiaddr, string, error) { + m := mux.NewRouter() + for path, handler := range handlers { + rpcServer := jsonrpc.NewServer() + rpcServer.Register("Filecoin", handler) + m.Handle(path, rpcServer) + } + testServ := httptest.NewServer(m) // todo: close t.Cleanup(testServ.Close) t.Cleanup(testServ.CloseClientConnections) diff --git a/paychmgr/mock_test.go b/paychmgr/mock_test.go index 3393a3072..2c891803b 100644 --- a/paychmgr/mock_test.go +++ b/paychmgr/mock_test.go @@ -8,6 +8,7 @@ import ( "github.com/ipfs/go-cid" "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/go-state-types/network" @@ -132,7 +133,7 @@ func newMockPaychAPI() *mockPaychAPI { } } -func (pchapi *mockPaychAPI) StateWaitMsg(ctx context.Context, mcid cid.Cid, confidence uint64) (*api.MsgLookup, error) { +func (pchapi *mockPaychAPI) StateWaitMsg(ctx context.Context, mcid cid.Cid, confidence uint64, limit abi.ChainEpoch, allowReplaced bool) (*api.MsgLookup, error) { pchapi.lk.Lock() response := make(chan types.MessageReceipt) diff --git a/storage/wdpost_run_test.go b/storage/wdpost_run_test.go index 4bf30e3e9..6a55bad1f 100644 --- a/storage/wdpost_run_test.go +++ b/storage/wdpost_run_test.go @@ -92,7 +92,7 @@ func (m *mockStorageMinerAPI) MpoolPushMessage(ctx context.Context, message *typ }, nil } -func (m *mockStorageMinerAPI) StateWaitMsg(ctx context.Context, cid cid.Cid, confidence uint64) (*api.MsgLookup, error) { +func (m *mockStorageMinerAPI) StateWaitMsg(ctx context.Context, cid cid.Cid, confidence uint64, limit abi.ChainEpoch, allowReplaced bool) (*api.MsgLookup, error) { return &api.MsgLookup{ Receipt: types.MessageReceipt{ ExitCode: 0, @@ -311,7 +311,7 @@ func (m *mockStorageMinerAPI) StateMinerInitialPledgeCollateral(ctx context.Cont panic("implement me") } -func (m *mockStorageMinerAPI) StateSearchMsg(ctx context.Context, cid cid.Cid) (*api.MsgLookup, error) { +func (m *mockStorageMinerAPI) StateSearchMsg(ctx context.Context, from types.TipSetKey, msg cid.Cid, limit abi.ChainEpoch, allowReplaced bool) (*api.MsgLookup, error) { panic("implement me") }