-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6642 from hunjixin/feat/add_getmessagesints_api
Add ChainGetMessagesInTipset API
- Loading branch information
Showing
14 changed files
with
238 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package itests | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/filecoin-project/lotus/api" | ||
"github.com/filecoin-project/lotus/chain/store" | ||
"github.com/filecoin-project/lotus/chain/types" | ||
"github.com/filecoin-project/lotus/itests/kit" | ||
"github.com/stretchr/testify/require" | ||
|
||
"time" | ||
|
||
"github.com/filecoin-project/go-state-types/big" | ||
) | ||
|
||
func TestChainGetMessagesInTs(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
kit.QuietMiningLogs() | ||
|
||
client, _, ens := kit.EnsembleMinimal(t, kit.MockProofs()) | ||
ens.InterconnectAll().BeginMining(10 * time.Millisecond) | ||
|
||
// create a new address where to send funds. | ||
addr, err := client.WalletNew(ctx, types.KTBLS) | ||
require.NoError(t, err) | ||
|
||
// get the existing balance from the default wallet to then split it. | ||
bal, err := client.WalletBalance(ctx, client.DefaultKey.Address) | ||
require.NoError(t, err) | ||
|
||
const iterations = 100 | ||
|
||
// we'll send half our balance (saving the other half for gas), | ||
// in `iterations` increments. | ||
toSend := big.Div(bal, big.NewInt(2)) | ||
each := big.Div(toSend, big.NewInt(iterations)) | ||
|
||
waitAllCh := make(chan struct{}) | ||
go func() { | ||
headChangeCh, err := client.ChainNotify(ctx) | ||
require.NoError(t, err) | ||
<-headChangeCh //skip hccurrent | ||
|
||
count := 0 | ||
for { | ||
select { | ||
case headChanges := <-headChangeCh: | ||
for _, change := range headChanges { | ||
if change.Type == store.HCApply { | ||
msgs, err := client.ChainGetMessagesInTipset(ctx, change.Val.Key()) | ||
require.NoError(t, err) | ||
count += len(msgs) | ||
if count == iterations { | ||
waitAllCh <- struct{}{} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}() | ||
|
||
var sms []*types.SignedMessage | ||
for i := 0; i < iterations; i++ { | ||
msg := &types.Message{ | ||
From: client.DefaultKey.Address, | ||
To: addr, | ||
Value: each, | ||
} | ||
|
||
sm, err := client.MpoolPushMessage(ctx, msg, nil) | ||
require.NoError(t, err) | ||
require.EqualValues(t, i, sm.Message.Nonce) | ||
|
||
sms = append(sms, sm) | ||
} | ||
|
||
select { | ||
case <-waitAllCh: | ||
case <-time.After(time.Minute): | ||
t.Errorf("timeout to wait for pack messages") | ||
} | ||
|
||
for _, sm := range sms { | ||
msgLookup, err := client.StateWaitMsg(ctx, sm.Cid(), 3, api.LookbackNoLimit, true) | ||
require.NoError(t, err) | ||
|
||
ts, err := client.ChainGetTipSet(ctx, msgLookup.TipSet) | ||
require.NoError(t, err) | ||
|
||
msgs, err := client.ChainGetMessagesInTipset(ctx, ts.Parents()) | ||
require.NoError(t, err) | ||
|
||
var found bool | ||
for _, msg := range msgs { | ||
if msg.Cid == sm.Cid() { | ||
found = true | ||
} | ||
} | ||
require.EqualValues(t, true, found, "expect got message in tipset %v", msgLookup.TipSet) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters