From 87cd8c672571ec22ae36b9eef1a42557e8546436 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Tue, 13 Oct 2020 17:48:54 +0200 Subject: [PATCH 1/3] Fix off by one tipset in searchBackForMsg This way we will return the tipset the message was executed in Signed-off-by: Jakub Sztandera --- chain/stmgr/stmgr.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chain/stmgr/stmgr.go b/chain/stmgr/stmgr.go index b470cfe83ad..0cb17fcf3ef 100644 --- a/chain/stmgr/stmgr.go +++ b/chain/stmgr/stmgr.go @@ -738,7 +738,7 @@ func (sm *StateManager) searchBackForMsg(ctx context.Context, from *types.TipSet } if r != nil { - return pts, r, foundMsg, nil + return cur, r, foundMsg, nil } } From 8987defb9d8ba19ecc9bc6cb675bb3740cbb6923 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Tue, 13 Oct 2020 19:20:11 +0200 Subject: [PATCH 2/3] Fix BLS message ChainLength add more detail to ValidForBlockInclusion Signed-off-by: Jakub Sztandera --- chain/types/message.go | 2 +- chain/types/signedmessage.go | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/chain/types/message.go b/chain/types/message.go index cbc7c1dad0f..c53ecc7c160 100644 --- a/chain/types/message.go +++ b/chain/types/message.go @@ -195,7 +195,7 @@ func (m *Message) ValidForBlockInclusion(minGas int64) error { // since prices might vary with time, this is technically semantic validation if m.GasLimit < minGas { - return xerrors.New("'GasLimit' field cannot be less than the cost of storing a message on chain") + return xerrors.Errorf("'GasLimit' field cannot be less than the cost of storing a message on chain %d < %d", m.GasLimit, minGas) } return nil diff --git a/chain/types/signedmessage.go b/chain/types/signedmessage.go index 7532bea35a2..c539ac24025 100644 --- a/chain/types/signedmessage.go +++ b/chain/types/signedmessage.go @@ -78,7 +78,14 @@ func (sm *SignedMessage) MarshalJSON() ([]byte, error) { } func (sm *SignedMessage) ChainLength() int { - ser, err := sm.Serialize() + var ser []byte + var err error + if sm.Signature.Type == crypto.SigTypeBLS { + // BLS chain message length doesn't include signature + ser, err = sm.Message.Serialize() + } else { + ser, err = sm.Serialize() + } if err != nil { panic(err) } From ce548c8f95aa7f3459ec58b8df27902579b6ef4e Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Tue, 13 Oct 2020 18:25:49 +0200 Subject: [PATCH 3/3] Add test Signed-off-by: Jakub Sztandera --- api/test/test.go | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/api/test/test.go b/api/test/test.go index 947f2bef43b..4074ce4a68e 100644 --- a/api/test/test.go +++ b/api/test/test.go @@ -3,8 +3,10 @@ package test import ( "context" "testing" + "time" "github.com/filecoin-project/lotus/chain/stmgr" + "github.com/filecoin-project/lotus/chain/types" "github.com/multiformats/go-multiaddr" @@ -12,6 +14,7 @@ import ( "github.com/stretchr/testify/require" "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" "github.com/filecoin-project/lotus/build" @@ -75,6 +78,7 @@ func TestApis(t *testing.T, b APIBuilder) { t.Run("testConnectTwo", ts.testConnectTwo) t.Run("testMining", ts.testMining) t.Run("testMiningReal", ts.testMiningReal) + t.Run("testSearchMsg", ts.testSearchMsg) } func DefaultFullOpts(nFull int) []FullNodeOpts { @@ -120,6 +124,49 @@ func (ts *testSuite) testVersion(t *testing.T) { require.Equal(t, v.Version, build.BuildVersion) } +func (ts *testSuite) testSearchMsg(t *testing.T) { + apis, miners := ts.makeNodes(t, OneFull, OneMiner) + + api := apis[0] + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + senderAddr, err := api.WalletDefaultAddress(ctx) + if err != nil { + t.Fatal(err) + } + + msg := &types.Message{ + From: senderAddr, + To: senderAddr, + Value: big.Zero(), + } + bm := NewBlockMiner(ctx, t, miners[0], 100*time.Millisecond) + bm.MineBlocks() + defer bm.Stop() + + sm, err := api.MpoolPushMessage(ctx, msg, nil) + if err != nil { + t.Fatal(err) + } + res, err := api.StateWaitMsg(ctx, sm.Cid(), 1) + if err != nil { + t.Fatal(err) + } + if res.Receipt.ExitCode != 0 { + t.Fatal("did not successfully send message") + } + + searchRes, err := api.StateSearchMsg(ctx, sm.Cid()) + if err != nil { + t.Fatal(err) + } + + if searchRes.TipSet != res.TipSet { + t.Fatalf("search ts: %s, different from wait ts: %s", searchRes.TipSet, res.TipSet) + } + +} + func (ts *testSuite) testID(t *testing.T) { ctx := context.Background() apis, _ := ts.makeNodes(t, OneFull, OneMiner)