Merge remote-tracking branch 'origin/master' into feat/nv13-1.11
This commit is contained in:
commit
a676da8a7e
126
api/test/verifreg.go
Normal file
126
api/test/verifreg.go
Normal file
@ -0,0 +1,126 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
lapi "github.com/filecoin-project/lotus/api"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors"
|
||||
"github.com/filecoin-project/lotus/chain/actors/builtin/verifreg"
|
||||
"github.com/filecoin-project/lotus/node/impl"
|
||||
verifreg4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/verifreg"
|
||||
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/filecoin-project/go-state-types/big"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
)
|
||||
|
||||
func AddVerifiedClient(t *testing.T, b APIBuilder) {
|
||||
|
||||
nodes, miners := b(t, []FullNodeOpts{FullNodeWithLatestActorsAt(-1)}, OneMiner)
|
||||
api := nodes[0].FullNode.(*impl.FullNodeAPI)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
//Get VRH
|
||||
vrh, err := api.StateVerifiedRegistryRootKey(ctx, types.TipSetKey{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
//Add verifier
|
||||
verifier, err := api.WalletDefaultAddress(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
params, err := actors.SerializeParams(&verifreg4.AddVerifierParams{Address: verifier, Allowance: big.NewInt(100000000000)})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
msg := &types.Message{
|
||||
To: verifreg.Address,
|
||||
From: vrh,
|
||||
Method: verifreg.Methods.AddVerifier,
|
||||
Params: params,
|
||||
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("AddVerifier failed: ", err)
|
||||
}
|
||||
res, err := api.StateWaitMsg(ctx, sm.Cid(), 1, lapi.LookbackNoLimit, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if res.Receipt.ExitCode != 0 {
|
||||
t.Fatal("did not successfully send message")
|
||||
}
|
||||
|
||||
//Assign datacap to a client
|
||||
datacap := big.NewInt(10000)
|
||||
clientAddress, err := api.WalletNew(ctx, types.KTBLS)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
params, err = actors.SerializeParams(&verifreg4.AddVerifiedClientParams{Address: clientAddress, Allowance: datacap})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
msg = &types.Message{
|
||||
To: verifreg.Address,
|
||||
From: verifier,
|
||||
Method: verifreg.Methods.AddVerifiedClient,
|
||||
Params: params,
|
||||
Value: big.Zero(),
|
||||
}
|
||||
|
||||
sm, err = api.MpoolPushMessage(ctx, msg, nil)
|
||||
if err != nil {
|
||||
t.Fatal("AddVerifiedClient faield: ", err)
|
||||
}
|
||||
res, err = api.StateWaitMsg(ctx, sm.Cid(), 1, lapi.LookbackNoLimit, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if res.Receipt.ExitCode != 0 {
|
||||
t.Fatal("did not successfully send message")
|
||||
}
|
||||
|
||||
//check datacap balance
|
||||
dcap, err := api.StateVerifiedClientStatus(ctx, clientAddress, types.EmptyTSK)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !dcap.Equals(datacap) {
|
||||
t.Fatal("")
|
||||
}
|
||||
|
||||
//try to assign datacap to the same client should fail for actor v4 and below
|
||||
params, err = actors.SerializeParams(&verifreg4.AddVerifiedClientParams{Address: clientAddress, Allowance: datacap})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
msg = &types.Message{
|
||||
To: verifreg.Address,
|
||||
From: verifier,
|
||||
Method: verifreg.Methods.AddVerifiedClient,
|
||||
Params: params,
|
||||
Value: big.Zero(),
|
||||
}
|
||||
|
||||
if _, err = api.MpoolPushMessage(ctx, msg, nil); !strings.Contains(err.Error(), "verified client already exists") {
|
||||
t.Fatal("Add datacap to an exist verified client should fail")
|
||||
}
|
||||
}
|
@ -81,13 +81,13 @@ func HandleIncomingBlocks(ctx context.Context, bsub *pubsub.Subscription, s *cha
|
||||
log.Debug("about to fetch messages for block from pubsub")
|
||||
bmsgs, err := FetchMessagesByCids(ctx, ses, blk.BlsMessages)
|
||||
if err != nil {
|
||||
log.Errorf("failed to fetch all bls messages for block received over pubusb: %s; source: %s", err, src)
|
||||
log.Errorf("failed to fetch all bls messages for block received over pubsub: %s; source: %s", err, src)
|
||||
return
|
||||
}
|
||||
|
||||
smsgs, err := FetchSignedMessagesByCids(ctx, ses, blk.SecpkMessages)
|
||||
if err != nil {
|
||||
log.Errorf("failed to fetch all secpk messages for block received over pubusb: %s; source: %s", err, src)
|
||||
log.Errorf("failed to fetch all secpk messages for block received over pubsub: %s; source: %s", err, src)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -301,3 +301,9 @@ func TestDeadlineToggling(t *testing.T) {
|
||||
|
||||
test.TestDeadlineToggling(t, builder.MockSbBuilder, 2*time.Millisecond)
|
||||
}
|
||||
|
||||
func TestVerifiedClientTopUp(t *testing.T) {
|
||||
logging.SetLogLevel("storageminer", "FATAL")
|
||||
logging.SetLogLevel("chain", "ERROR")
|
||||
test.AddVerifiedClient(t, builder.MockSbBuilder)
|
||||
}
|
||||
|
@ -278,13 +278,26 @@ func mockBuilderOpts(t *testing.T, fullOpts []test.FullNodeOpts, storage []test.
|
||||
maddrs = append(maddrs, maddr)
|
||||
genms = append(genms, *genm)
|
||||
}
|
||||
|
||||
rkhKey, err := wallet.GenerateKey(types.KTSecp256k1)
|
||||
if err != nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
vrk := genesis.Actor{
|
||||
Type: genesis.TAccount,
|
||||
Balance: big.Mul(big.Div(big.NewInt(int64(build.FilBase)), big.NewInt(100)), big.NewInt(int64(build.FilecoinPrecision))),
|
||||
Meta: (&genesis.AccountMeta{Owner: rkhKey.Address}).ActorMeta(),
|
||||
}
|
||||
keys = append(keys, rkhKey)
|
||||
|
||||
templ := &genesis.Template{
|
||||
NetworkVersion: network.Version0,
|
||||
Accounts: genaccs,
|
||||
Miners: genms,
|
||||
NetworkName: "test",
|
||||
Timestamp: uint64(time.Now().Unix() - 10000), // some time sufficiently far in the past
|
||||
VerifregRootKey: gen.DefaultVerifregRootkeyActor,
|
||||
VerifregRootKey: vrk,
|
||||
RemainderAccount: gen.DefaultRemainderAccountActor,
|
||||
}
|
||||
|
||||
@ -309,6 +322,7 @@ func mockBuilderOpts(t *testing.T, fullOpts []test.FullNodeOpts, storage []test.
|
||||
|
||||
fullOpts[i].Opts(fulls),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -322,6 +336,10 @@ func mockBuilderOpts(t *testing.T, fullOpts []test.FullNodeOpts, storage []test.
|
||||
fulls[i].Stb = storageBuilder(fulls[i], mn, node.Options())
|
||||
}
|
||||
|
||||
if _, err := fulls[0].FullNode.WalletImport(ctx, &rkhKey.KeyInfo); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for i, def := range storage {
|
||||
// TODO: support non-bootstrap miners
|
||||
if i != 0 {
|
||||
@ -442,13 +460,26 @@ func mockSbBuilderOpts(t *testing.T, fullOpts []test.FullNodeOpts, storage []tes
|
||||
maddrs = append(maddrs, maddr)
|
||||
genms = append(genms, *genm)
|
||||
}
|
||||
|
||||
rkhKey, err := wallet.GenerateKey(types.KTSecp256k1)
|
||||
if err != nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
vrk := genesis.Actor{
|
||||
Type: genesis.TAccount,
|
||||
Balance: big.Mul(big.Div(big.NewInt(int64(build.FilBase)), big.NewInt(100)), big.NewInt(int64(build.FilecoinPrecision))),
|
||||
Meta: (&genesis.AccountMeta{Owner: rkhKey.Address}).ActorMeta(),
|
||||
}
|
||||
keys = append(keys, rkhKey)
|
||||
|
||||
templ := &genesis.Template{
|
||||
NetworkVersion: network.Version0,
|
||||
Accounts: genaccs,
|
||||
Miners: genms,
|
||||
NetworkName: "test",
|
||||
Timestamp: uint64(time.Now().Unix()) - (build.BlockDelaySecs * 20000),
|
||||
VerifregRootKey: gen.DefaultVerifregRootkeyActor,
|
||||
VerifregRootKey: vrk,
|
||||
RemainderAccount: gen.DefaultRemainderAccountActor,
|
||||
}
|
||||
|
||||
@ -499,6 +530,10 @@ func mockSbBuilderOpts(t *testing.T, fullOpts []test.FullNodeOpts, storage []tes
|
||||
))
|
||||
}
|
||||
|
||||
if _, err := fulls[0].FullNode.WalletImport(ctx, &rkhKey.KeyInfo); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for i, def := range storage {
|
||||
// TODO: support non-bootstrap miners
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user