-
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 #4246 from filecoin-project/feat/optim-search-msg
Optimize SearchForMessage and GetReceipt
- Loading branch information
Showing
4 changed files
with
121 additions
and
38 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
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,63 @@ | ||
package sub | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
address "github.com/filecoin-project/go-address" | ||
"github.com/filecoin-project/lotus/chain/types" | ||
blocks "github.com/ipfs/go-block-format" | ||
"github.com/ipfs/go-cid" | ||
) | ||
|
||
type getter struct { | ||
msgs []*types.Message | ||
} | ||
|
||
func (g *getter) GetBlock(ctx context.Context, c cid.Cid) (blocks.Block, error) { panic("NYI") } | ||
|
||
func (g *getter) GetBlocks(ctx context.Context, ks []cid.Cid) <-chan blocks.Block { | ||
ch := make(chan blocks.Block, len(g.msgs)) | ||
for _, m := range g.msgs { | ||
by, err := m.Serialize() | ||
if err != nil { | ||
panic(err) | ||
} | ||
b, err := blocks.NewBlockWithCid(by, m.Cid()) | ||
if err != nil { | ||
panic(err) | ||
} | ||
ch <- b | ||
} | ||
close(ch) | ||
return ch | ||
} | ||
|
||
func TestFetchCidsWithDedup(t *testing.T) { | ||
msgs := []*types.Message{} | ||
for i := 0; i < 10; i++ { | ||
msgs = append(msgs, &types.Message{ | ||
From: address.TestAddress, | ||
To: address.TestAddress, | ||
|
||
Nonce: uint64(i), | ||
}) | ||
} | ||
cids := []cid.Cid{} | ||
for _, m := range msgs { | ||
cids = append(cids, m.Cid()) | ||
} | ||
g := &getter{msgs} | ||
|
||
// the cids have a duplicate | ||
res, err := FetchMessagesByCids(context.TODO(), g, append(cids, cids[0])) | ||
|
||
t.Logf("err: %+v", err) | ||
t.Logf("res: %+v", res) | ||
if err == nil { | ||
t.Errorf("there should be an error") | ||
} | ||
if err == nil && (res[0] == nil || res[len(res)-1] == nil) { | ||
t.Fatalf("there is a nil message: first %p, last %p", res[0], res[len(res)-1]) | ||
} | ||
} |
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