Skip to content

Commit

Permalink
Merge pull request #9206 from filecoin-project/asr/verifreg-tuple
Browse files Browse the repository at this point in the history
fix: verifreg: serialize RmDcProposalID as int, not tuple
  • Loading branch information
jennijuju authored Aug 26, 2022
2 parents 45d1bd6 + 343d092 commit 1b5a1f6
Show file tree
Hide file tree
Showing 7 changed files with 256 additions and 25 deletions.
2 changes: 1 addition & 1 deletion chain/vm/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (rt *Runtime) shimCall(f func() interface{}) (rval []byte, aerr aerrors.Act
if rt.NetworkVersion() <= network.Version3 {
aerr = aerrors.Newf(1, "spec actors failure: %s", r)
} else {
aerr = aerrors.Newf(exitcode.SysErrReserved1, "spec actors failure: %s", r)
aerr = aerrors.Newf(exitcode.SysErrIllegalInstruction, "spec actors failure: %s", r)
}
}
}()
Expand Down
2 changes: 1 addition & 1 deletion cli/filplus.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ var filplusSignRemoveDataCapProposal = &cli.Command{
}

params := verifregtypes.RemoveDataCapProposal{
RemovalProposalID: verifregtypes.RmDcProposalID{ProposalID: id},
RemovalProposalID: id,
DataCapAmount: allowanceToRemove,
VerifiedClient: clientIdAddr,
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ require (
github.com/filecoin-project/go-legs v0.4.4
github.com/filecoin-project/go-padreader v0.0.1
github.com/filecoin-project/go-paramfetch v0.0.4
github.com/filecoin-project/go-state-types v0.1.10
github.com/filecoin-project/go-state-types v0.1.11
github.com/filecoin-project/go-statemachine v1.0.2
github.com/filecoin-project/go-statestore v0.2.0
github.com/filecoin-project/go-storedcounter v0.1.0
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,9 @@ github.com/filecoin-project/go-state-types v0.1.3/go.mod h1:ezYnPf0bNkTsDibL/psS
github.com/filecoin-project/go-state-types v0.1.5/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
github.com/filecoin-project/go-state-types v0.1.6/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
github.com/filecoin-project/go-state-types v0.1.8/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
github.com/filecoin-project/go-state-types v0.1.10 h1:YrrJWWh2fU4VPhwHyPlDK5I4mB7bqgnRd3HCm9IOwIU=
github.com/filecoin-project/go-state-types v0.1.10/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
github.com/filecoin-project/go-state-types v0.1.11 h1:QzKUILRGa9gjJKPCiFlvCfcDGK2IqtJ6CpRQULvZZpA=
github.com/filecoin-project/go-state-types v0.1.11/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
github.com/filecoin-project/go-statemachine v0.0.0-20200925024713-05bd7c71fbfe/go.mod h1:FGwQgZAt2Gh5mjlwJUlVB62JeYdo+if0xWxSEfBD9ig=
github.com/filecoin-project/go-statemachine v1.0.2-0.20220322104818-27f8fbb86dfd/go.mod h1:jZdXXiHa61n4NmgWFG4w8tnqgvZVHYbJ3yW7+y8bF54=
github.com/filecoin-project/go-statemachine v1.0.2 h1:421SSWBk8GIoCoWYYTE/d+qCWccgmRH0uXotXRDjUbc=
Expand Down
232 changes: 228 additions & 4 deletions itests/verifreg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package itests

import (
"bytes"
"context"
"fmt"
"strings"
Expand All @@ -10,10 +11,11 @@ import (

"github.com/stretchr/testify/require"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
verifregst "github.com/filecoin-project/go-state-types/builtin/v8/verifreg"
"github.com/filecoin-project/go-state-types/network"
verifreg4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/verifreg"

lapi "github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain/actors"
Expand Down Expand Up @@ -76,7 +78,7 @@ func TestVerifiedClientTopUp(t *testing.T) {
verifiedClientAddr, err := api.WalletImport(ctx, &verifiedClientKey.KeyInfo)
require.NoError(t, err)

params, err := actors.SerializeParams(&verifreg4.AddVerifierParams{Address: verifierAddr, Allowance: big.NewInt(100000000000)})
params, err := actors.SerializeParams(&verifregst.AddVerifierParams{Address: verifierAddr, Allowance: big.NewInt(100000000000)})
require.NoError(t, err)

msg := &types.Message{
Expand All @@ -98,7 +100,7 @@ func TestVerifiedClientTopUp(t *testing.T) {
// assign datacap to a client
datacap := big.NewInt(10000)

params, err = actors.SerializeParams(&verifreg4.AddVerifiedClientParams{Address: verifiedClientAddr, Allowance: datacap})
params, err = actors.SerializeParams(&verifregst.AddVerifiedClientParams{Address: verifiedClientAddr, Allowance: datacap})
require.NoError(t, err)

msg = &types.Message{
Expand Down Expand Up @@ -127,7 +129,7 @@ func TestVerifiedClientTopUp(t *testing.T) {
}

// try to assign datacap to the same client should fail for actor v4 and below
params, err = actors.SerializeParams(&verifreg4.AddVerifiedClientParams{Address: verifiedClientAddr, Allowance: datacap})
params, err = actors.SerializeParams(&verifregst.AddVerifiedClientParams{Address: verifiedClientAddr, Allowance: datacap})
if err != nil {
t.Fatal(err)
}
Expand All @@ -154,3 +156,225 @@ func TestVerifiedClientTopUp(t *testing.T) {
t.Run("nv12", test(network.Version12, false))
t.Run("nv13", test(network.Version13, true))
}

func TestRemoveDataCap(t *testing.T) {
//stm: @CHAIN_SYNCER_LOAD_GENESIS_001, @CHAIN_SYNCER_FETCH_TIPSET_001,
//stm: @CHAIN_SYNCER_START_001, @CHAIN_SYNCER_SYNC_001, @BLOCKCHAIN_BEACON_VALIDATE_BLOCK_VALUES_01
//stm: @CHAIN_SYNCER_COLLECT_CHAIN_001, @CHAIN_SYNCER_COLLECT_HEADERS_001, @CHAIN_SYNCER_VALIDATE_TIPSET_001
//stm: @CHAIN_SYNCER_NEW_PEER_HEAD_001, @CHAIN_SYNCER_VALIDATE_MESSAGE_META_001, @CHAIN_SYNCER_STOP_001

//stm: @CHAIN_INCOMING_HANDLE_INCOMING_BLOCKS_001, @CHAIN_INCOMING_VALIDATE_BLOCK_PUBSUB_001, @CHAIN_INCOMING_VALIDATE_MESSAGE_PUBSUB_001
blockTime := 100 * time.Millisecond

rootKey, err := key.GenerateKey(types.KTSecp256k1)
require.NoError(t, err)

verifier1Key, err := key.GenerateKey(types.KTSecp256k1)
require.NoError(t, err)

verifier2Key, err := key.GenerateKey(types.KTSecp256k1)
require.NoError(t, err)

verifiedClientKey, err := key.GenerateKey(types.KTBLS)
require.NoError(t, err)

bal, err := types.ParseFIL("100fil")
require.NoError(t, err)

node, _, ens := kit.EnsembleMinimal(t, kit.MockProofs(),
kit.RootVerifier(rootKey, abi.NewTokenAmount(bal.Int64())),
kit.Account(verifier1Key, abi.NewTokenAmount(bal.Int64())),
kit.Account(verifier2Key, abi.NewTokenAmount(bal.Int64())),
kit.Account(verifiedClientKey, abi.NewTokenAmount(bal.Int64())),
)

ens.InterconnectAll().BeginMining(blockTime)

api := node.FullNode.(*impl.FullNodeAPI)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// get VRH
//stm: @CHAIN_STATE_VERIFIED_REGISTRY_ROOT_KEY_001
vrh, err := api.StateVerifiedRegistryRootKey(ctx, types.TipSetKey{})
fmt.Println(vrh.String())
require.NoError(t, err)

// import the root key.
rootAddr, err := api.WalletImport(ctx, &rootKey.KeyInfo)
require.NoError(t, err)

// import the verifiers' keys.
verifier1Addr, err := api.WalletImport(ctx, &verifier1Key.KeyInfo)
require.NoError(t, err)

verifier2Addr, err := api.WalletImport(ctx, &verifier2Key.KeyInfo)
require.NoError(t, err)

// import the verified client's key.
verifiedClientAddr, err := api.WalletImport(ctx, &verifiedClientKey.KeyInfo)
require.NoError(t, err)

// resolve all keys

verifier1ID, err := api.StateLookupID(ctx, verifier1Addr, types.EmptyTSK)
require.NoError(t, err)

verifier2ID, err := api.StateLookupID(ctx, verifier2Addr, types.EmptyTSK)
require.NoError(t, err)

verifiedClientID, err := api.StateLookupID(ctx, verifiedClientAddr, types.EmptyTSK)
require.NoError(t, err)

// make the 2 verifiers

makeVerifier := func(addr address.Address) error {
params, aerr := actors.SerializeParams(&verifregst.AddVerifierParams{Address: addr, Allowance: big.NewInt(100000000000)})
require.NoError(t, aerr)

msg := &types.Message{
From: rootAddr,
To: verifreg.Address,
Method: verifreg.Methods.AddVerifier,
Params: params,
Value: big.Zero(),
}

sm, err := api.MpoolPushMessage(ctx, msg, nil)
require.NoError(t, err, "AddVerifier failed")

//stm: @CHAIN_STATE_WAIT_MSG_001
res, err := api.StateWaitMsg(ctx, sm.Cid(), 1, lapi.LookbackNoLimit, true)
require.NoError(t, err)
require.EqualValues(t, 0, res.Receipt.ExitCode)

return nil
}

require.NoError(t, makeVerifier(verifier1Addr))
require.NoError(t, makeVerifier(verifier2Addr))

// assign datacap to a client
datacap := big.NewInt(10000)

params, err := actors.SerializeParams(&verifregst.AddVerifiedClientParams{Address: verifiedClientAddr, Allowance: datacap})
require.NoError(t, err)

msg := &types.Message{
From: verifier1Addr,
To: verifreg.Address,
Method: verifreg.Methods.AddVerifiedClient,
Params: params,
Value: big.Zero(),
}

sm, err := api.MpoolPushMessage(ctx, msg, nil)
require.NoError(t, err)

//stm: @CHAIN_STATE_WAIT_MSG_001
res, err := api.StateWaitMsg(ctx, sm.Cid(), 1, lapi.LookbackNoLimit, true)
require.NoError(t, err)
require.EqualValues(t, 0, res.Receipt.ExitCode)

// check datacap balance
//stm: @CHAIN_STATE_VERIFIED_CLIENT_STATUS_001
dcap, err := api.StateVerifiedClientStatus(ctx, verifiedClientAddr, types.EmptyTSK)
require.NoError(t, err)

if !dcap.Equals(datacap) {
t.Fatal("unexpected datacap")
}

// helper to create removedatacap message
makeRemoveDatacapMsg := func(removeDatacap big.Int, proposalID uint64) *types.Message {
removeProposal := verifregst.RemoveDataCapProposal{
VerifiedClient: verifiedClientID,
DataCapAmount: removeDatacap,
RemovalProposalID: proposalID,
}

buf := bytes.Buffer{}
buf.WriteString(verifregst.SignatureDomainSeparation_RemoveDataCap)
require.NoError(t, removeProposal.MarshalCBOR(&buf), "failed to marshal proposal")

removeProposalSer := buf.Bytes()

verifier1Sig, err := api.WalletSign(ctx, verifier1Addr, removeProposalSer)
require.NoError(t, err, "failed to sign proposal")

removeRequest1 := verifregst.RemoveDataCapRequest{
Verifier: verifier1ID,
VerifierSignature: *verifier1Sig,
}

verifier2Sig, err := api.WalletSign(ctx, verifier2Addr, removeProposalSer)
require.NoError(t, err, "failed to sign proposal")

removeRequest2 := verifregst.RemoveDataCapRequest{
Verifier: verifier2ID,
VerifierSignature: *verifier2Sig,
}

removeDataCapParams := verifregst.RemoveDataCapParams{
VerifiedClientToRemove: verifiedClientAddr,
DataCapAmountToRemove: removeDatacap,
VerifierRequest1: removeRequest1,
VerifierRequest2: removeRequest2,
}

params, aerr := actors.SerializeParams(&removeDataCapParams)
require.NoError(t, aerr)

msg = &types.Message{
From: rootAddr,
To: verifreg.Address,
Method: verifreg.Methods.RemoveVerifiedClientDataCap,
Params: params,
Value: big.Zero(),
}

return msg
}

// let's take away half the client's datacap now

removeDatacap := big.Div(datacap, big.NewInt(2))
// proposal ids are 0 the first time
removeMsg := makeRemoveDatacapMsg(removeDatacap, 0)

sm, err = api.MpoolPushMessage(ctx, removeMsg, nil)
require.NoError(t, err, "RemoveDataCap failed")

//stm: @CHAIN_STATE_WAIT_MSG_001
res, err = api.StateWaitMsg(ctx, sm.Cid(), 1, lapi.LookbackNoLimit, true)
require.NoError(t, err)
require.EqualValues(t, 0, res.Receipt.ExitCode)

// check datacap balance
//stm: @CHAIN_STATE_VERIFIED_CLIENT_STATUS_001
dcap, err = api.StateVerifiedClientStatus(ctx, verifiedClientAddr, types.EmptyTSK)
require.NoError(t, err)

if !dcap.Equals(big.Sub(datacap, removeDatacap)) {
t.Fatal("unexpected datacap")
}

// now take away the second half!

// proposal ids are 1 the second time
removeMsg = makeRemoveDatacapMsg(removeDatacap, 1)

sm, err = api.MpoolPushMessage(ctx, removeMsg, nil)
require.NoError(t, err, "RemoveDataCap failed")

//stm: @CHAIN_STATE_WAIT_MSG_001
res, err = api.StateWaitMsg(ctx, sm.Cid(), 1, lapi.LookbackNoLimit, true)
require.NoError(t, err)
require.EqualValues(t, 0, res.Receipt.ExitCode)

// check datacap balance
//stm: @CHAIN_STATE_VERIFIED_CLIENT_STATUS_001
dcap, err = api.StateVerifiedClientStatus(ctx, verifiedClientAddr, types.EmptyTSK)
require.NoError(t, err)
require.Nil(t, dcap, "expected datacap to be nil")
}
16 changes: 8 additions & 8 deletions testplans/lotus-soup/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ require (
github.com/drand/drand v1.3.0
github.com/filecoin-project/go-address v1.0.0
github.com/filecoin-project/go-data-transfer v1.15.2
github.com/filecoin-project/go-fil-markets v1.23.1
github.com/filecoin-project/go-fil-markets v1.24.0
github.com/filecoin-project/go-jsonrpc v0.1.5
github.com/filecoin-project/go-state-types v0.1.10
github.com/filecoin-project/go-state-types v0.1.11-0.20220823184028-73c63d4127a4
github.com/filecoin-project/go-storedcounter v0.1.0
github.com/filecoin-project/lotus v0.0.0-00010101000000-000000000000
github.com/filecoin-project/specs-actors v0.9.15
Expand Down Expand Up @@ -149,9 +149,9 @@ require (
github.com/influxdata/influxdb1-client v0.0.0-20200827194710-b269163b24ab // indirect
github.com/ipfs/bbloom v0.0.4 // indirect
github.com/ipfs/go-bitfield v1.0.0 // indirect
github.com/ipfs/go-bitswap v0.7.1-0.20220705171910-84973686518b // indirect
github.com/ipfs/go-bitswap v0.8.0 // indirect
github.com/ipfs/go-block-format v0.0.3 // indirect
github.com/ipfs/go-blockservice v0.3.0 // indirect
github.com/ipfs/go-blockservice v0.4.0 // indirect
github.com/ipfs/go-cidutil v0.1.0 // indirect
github.com/ipfs/go-ds-badger2 v0.1.2 // indirect
github.com/ipfs/go-ds-leveldb v0.5.0 // indirect
Expand All @@ -164,8 +164,8 @@ require (
github.com/ipfs/go-ipfs-cmds v0.7.0 // indirect
github.com/ipfs/go-ipfs-delay v0.0.1 // indirect
github.com/ipfs/go-ipfs-ds-help v1.1.0 // indirect
github.com/ipfs/go-ipfs-exchange-interface v0.1.0 // indirect
github.com/ipfs/go-ipfs-exchange-offline v0.2.0 // indirect
github.com/ipfs/go-ipfs-exchange-interface v0.2.0 // indirect
github.com/ipfs/go-ipfs-exchange-offline v0.3.0 // indirect
github.com/ipfs/go-ipfs-http-client v0.4.0 // indirect
github.com/ipfs/go-ipfs-posinfo v0.0.1 // indirect
github.com/ipfs/go-ipfs-pq v0.0.2 // indirect
Expand Down Expand Up @@ -206,14 +206,14 @@ require (
github.com/libp2p/go-libp2p-connmgr v0.4.0 // indirect
github.com/libp2p/go-libp2p-discovery v0.7.0 // indirect
github.com/libp2p/go-libp2p-gostream v0.4.0 // indirect
github.com/libp2p/go-libp2p-kad-dht v0.15.0 // indirect
github.com/libp2p/go-libp2p-kad-dht v0.17.0 // indirect
github.com/libp2p/go-libp2p-kbucket v0.4.7 // indirect
github.com/libp2p/go-libp2p-loggables v0.1.0 // indirect
github.com/libp2p/go-libp2p-noise v0.5.0 // indirect
github.com/libp2p/go-libp2p-peerstore v0.7.1 // indirect
github.com/libp2p/go-libp2p-pubsub v0.7.1 // indirect
github.com/libp2p/go-libp2p-record v0.1.3 // indirect
github.com/libp2p/go-libp2p-resource-manager v0.5.2 // indirect
github.com/libp2p/go-libp2p-resource-manager v0.5.3 // indirect
github.com/libp2p/go-libp2p-routing-helpers v0.2.3 // indirect
github.com/libp2p/go-libp2p-tls v0.5.0 // indirect
github.com/libp2p/go-maddr-filter v0.1.0 // indirect
Expand Down
Loading

0 comments on commit 1b5a1f6

Please sign in to comment.