2022-08-29 14:25:30 +00:00
|
|
|
// stm: #integration
|
2020-01-31 23:51:15 +00:00
|
|
|
package stmgr_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
2023-02-15 21:24:21 +00:00
|
|
|
"os"
|
2021-01-27 02:45:50 +00:00
|
|
|
"sync"
|
2020-01-31 23:51:15 +00:00
|
|
|
"testing"
|
|
|
|
|
2020-10-08 23:33:50 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
2023-02-27 17:27:48 +00:00
|
|
|
"github.com/ipfs/go-datastore"
|
2020-10-08 23:33:50 +00:00
|
|
|
ipldcbor "github.com/ipfs/go-ipld-cbor"
|
2021-04-06 13:04:32 +00:00
|
|
|
logging "github.com/ipfs/go-log/v2"
|
2020-10-08 23:33:50 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
cbg "github.com/whyrusleeping/cbor-gen"
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
2020-01-31 23:51:15 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
2020-09-07 03:49:10 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2022-10-13 15:07:34 +00:00
|
|
|
actorstypes "github.com/filecoin-project/go-state-types/actors"
|
2020-09-28 19:48:08 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/cbor"
|
2021-07-16 19:17:16 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/network"
|
2022-09-21 14:56:58 +00:00
|
|
|
rtt "github.com/filecoin-project/go-state-types/rt"
|
2020-10-15 00:29:25 +00:00
|
|
|
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
|
2020-10-08 01:09:33 +00:00
|
|
|
init2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/init"
|
|
|
|
rt2 "github.com/filecoin-project/specs-actors/v2/actors/runtime"
|
2020-02-10 19:16:36 +00:00
|
|
|
|
2020-10-08 23:33:50 +00:00
|
|
|
"github.com/filecoin-project/lotus/api"
|
2020-01-31 23:51:15 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors"
|
|
|
|
"github.com/filecoin-project/lotus/chain/actors/aerrors"
|
2022-09-21 14:56:58 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
2020-10-08 20:32:54 +00:00
|
|
|
_init "github.com/filecoin-project/lotus/chain/actors/builtin/init"
|
2020-09-23 19:24:51 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors/policy"
|
2022-09-27 10:21:42 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/consensus"
|
2021-09-02 16:07:23 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/consensus/filcns"
|
2020-01-31 23:51:15 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/gen"
|
2023-03-12 13:33:36 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/index"
|
2023-02-27 17:27:48 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/stmgr"
|
2020-01-31 23:51:15 +00:00
|
|
|
. "github.com/filecoin-project/lotus/chain/stmgr"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
"github.com/filecoin-project/lotus/chain/vm"
|
2020-02-07 07:01:37 +00:00
|
|
|
_ "github.com/filecoin-project/lotus/lib/sigs/bls"
|
|
|
|
_ "github.com/filecoin-project/lotus/lib/sigs/secp"
|
2020-01-31 23:51:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2020-09-23 19:24:51 +00:00
|
|
|
policy.SetSupportedProofTypes(abi.RegisteredSealProof_StackedDrg2KiBV1)
|
|
|
|
policy.SetConsensusMinerMinPower(abi.NewStoragePower(2048))
|
|
|
|
policy.SetMinVerifiedDealSize(abi.NewStoragePower(256))
|
2020-01-31 23:51:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const testForkHeight = 40
|
|
|
|
|
|
|
|
type testActor struct {
|
|
|
|
}
|
|
|
|
|
2023-03-23 15:17:46 +00:00
|
|
|
type mockExecutor struct {
|
|
|
|
vm.Interface
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*mockExecutor) Done() {}
|
|
|
|
|
2020-09-28 21:43:55 +00:00
|
|
|
// must use existing actor that an account is allowed to exec.
|
2020-10-15 00:29:25 +00:00
|
|
|
func (testActor) Code() cid.Cid { return builtin0.PaymentChannelActorCodeID }
|
2020-09-28 19:48:08 +00:00
|
|
|
func (testActor) State() cbor.Er { return new(testActorState) }
|
|
|
|
|
2020-01-31 23:51:15 +00:00
|
|
|
type testActorState struct {
|
|
|
|
HasUpgraded uint64
|
|
|
|
}
|
|
|
|
|
|
|
|
func (tas *testActorState) MarshalCBOR(w io.Writer) error {
|
|
|
|
return cbg.CborWriteHeader(w, cbg.MajUnsignedInt, tas.HasUpgraded)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (tas *testActorState) UnmarshalCBOR(r io.Reader) error {
|
|
|
|
t, v, err := cbg.CborReadHeader(r)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if t != cbg.MajUnsignedInt {
|
2020-02-29 01:12:47 +00:00
|
|
|
return fmt.Errorf("wrong type in test actor state (got %d)", t)
|
2020-01-31 23:51:15 +00:00
|
|
|
}
|
|
|
|
tas.HasUpgraded = v
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-09-28 19:48:08 +00:00
|
|
|
func (ta testActor) Exports() []interface{} {
|
2020-01-31 23:51:15 +00:00
|
|
|
return []interface{}{
|
|
|
|
1: ta.Constructor,
|
|
|
|
2: ta.TestMethod,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-08 01:09:33 +00:00
|
|
|
func (ta *testActor) Constructor(rt rt2.Runtime, params *abi.EmptyValue) *abi.EmptyValue {
|
2020-04-28 02:46:44 +00:00
|
|
|
rt.ValidateImmediateCallerAcceptAny()
|
2020-09-14 19:41:55 +00:00
|
|
|
rt.StateCreate(&testActorState{11})
|
2020-10-07 22:28:16 +00:00
|
|
|
//fmt.Println("NEW ACTOR ADDRESS IS: ", rt.Receiver())
|
2020-01-31 23:51:15 +00:00
|
|
|
|
2020-09-10 06:30:47 +00:00
|
|
|
return abi.Empty
|
2020-01-31 23:51:15 +00:00
|
|
|
}
|
|
|
|
|
2020-10-08 01:09:33 +00:00
|
|
|
func (ta *testActor) TestMethod(rt rt2.Runtime, params *abi.EmptyValue) *abi.EmptyValue {
|
2020-04-28 02:46:44 +00:00
|
|
|
rt.ValidateImmediateCallerAcceptAny()
|
2020-01-31 23:51:15 +00:00
|
|
|
var st testActorState
|
2020-09-14 19:41:55 +00:00
|
|
|
rt.StateReadonly(&st)
|
2020-01-31 23:51:15 +00:00
|
|
|
|
2020-02-29 01:12:47 +00:00
|
|
|
if rt.CurrEpoch() > testForkHeight {
|
2020-01-31 23:51:15 +00:00
|
|
|
if st.HasUpgraded != 55 {
|
2020-02-29 01:12:47 +00:00
|
|
|
panic(aerrors.Fatal("fork updating applied in wrong order"))
|
2020-01-31 23:51:15 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if st.HasUpgraded != 11 {
|
2020-02-29 01:12:47 +00:00
|
|
|
panic(aerrors.Fatal("fork updating happened too early"))
|
2020-01-31 23:51:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-10 06:30:47 +00:00
|
|
|
return abi.Empty
|
2020-01-31 23:51:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestForkHeightTriggers(t *testing.T) {
|
feat: Add additional test annotations (#8272)
* Annotate api,proxy_util,blockstore_badger, policy tests
* Annotate splitstore: bsbadger / markset
* Annotate splitstore feature
* Annotate union/timed blockstore tests
* Annotate openrpc, diff_adt tests
* Annotate error,drand,events tests
* Annotate predicates_test
* Fix annotations
* Annotate tscache, gen tests
* Annotate fundmanager test
* Annotate repub and selection tests
* Annotate statetree_test
* Annotate forks_test
* Annotate searchwait_test.go
* Fix duplicated @@ symbols
* Annotate chain stmgr/store tests
* Annotate more (types) tests
* More tests annotated
* Annotate conformance chaos actor tests
* Annotate more integration tests
* Annotate journal system tests
* Annotate more tests.
* Annotate gas,head buffer behaviors
* Fix markset annotations
* doc: test annotations for the markets dagstore wrapper
* Annotate miner_api test in dagstore
* Annotate more test files
* Remove bad annotations from fsrepo
* Annotate wdpost system
* Remove bad annotations
* Renamce "conformance" to "chaos_actor" tests
* doc: stm annotations for blockheader & election proof tests
* Annotate remaining "A" tests
* annotate: stm for error_test
* memrepo_test.go
* Annotate "b" file tests
* message_test.go
* doc: stm annotate for fsrepo_test
* Annotate "c" file tests
* Annotate "D" test files
* message_test.go
* doc: stm annotate for chain, node/config & client
* docs: stm annotate node_test
* Annotate u,v,wl tests
* doc: stm annotations for various test files
* Annotate "T" test files
* doc: stm annotate for proxy_util_test & policy_test
* doc: stm annotate for various tests
* doc: final few stm annotations
* Add mempool unit tests
* Add two more memPool Add tests
* Update submodules
* Add check function tests
* Add stm annotations, refactor test helper
* Annotate api,proxy_util,blockstore_badger, policy tests
* Annotate splitstore: bsbadger / markset
solving merge conflicts
* Annotate splitstore feature
* Annotate union/timed blockstore tests
* Annotate openrpc, diff_adt tests
* Annotate error,drand,events tests
* Annotate predicates_test
* Fix annotations
* Annotate tscache, gen tests
* Annotate fundmanager test
* Annotate statetree_test
* Annotate forks_test
* Annotate searchwait_test.go
* Fix duplicated @@ symbols
* Annotate chain stmgr/store tests
* Annotate more (types) tests
* More tests annotated
* Annotate conformance chaos actor tests
* Annotate more integration tests
* Annotate journal system tests
* Annotate more tests.
* Annotate gas,head buffer behaviors
solve merge conflict
* Fix markset annotations
* Annotate miner_api test in dagstore
* Annotate more test files
* doc: test annotations for the markets dagstore wrapper
* Annotate wdpost system
* Renamce "conformance" to "chaos_actor" tests
* Annotate remaining "A" tests
* doc: stm annotations for blockheader & election proof tests
* annotate: stm for error_test
* Annotate "b" file tests
* memrepo_test.go
* Annotate "c" file tests
* message_test.go
* Annotate "D" test files
* doc: stm annotate for fsrepo_test
* Annotate u,v,wl tests
* message_test.go
* doc: stm annotate for chain, node/config & client
* docs: stm annotate node_test
* Annotate "T" test files
* doc: stm annotations for various test files
* Add mempool unit tests
solve merge conflict
* doc: stm annotate for proxy_util_test & policy_test
* doc: stm annotate for various tests
* doc: final few stm annotations
* Add two more memPool Add tests
* Update submodules
* Add check function tests
solve conflict
* Add stm annotations, refactor test helper
solve merge conflict
* Change CLI test kinds to "unit"
* Fix double merged test
* Fix ccupgrade_test merge
* Fix lint issues
* Add stm annotation to types_Test
* Test vectors submodule
* Add file annotation to burn_test
Co-authored-by: Nikola Divic <divicnikola@gmail.com>
Co-authored-by: TheMenko <themenkoprojects@gmail.com>
2022-03-16 17:37:34 +00:00
|
|
|
//stm: @CHAIN_STATETREE_GET_ACTOR_001, @CHAIN_STATETREE_FLUSH_001, @TOKEN_WALLET_SIGN_001
|
|
|
|
//stm: @CHAIN_GEN_NEXT_TIPSET_001
|
|
|
|
//stm: @CHAIN_STATE_RESOLVE_TO_KEY_ADDR_001, @CHAIN_STATE_SET_VM_CONSTRUCTOR_001
|
2020-01-31 23:51:15 +00:00
|
|
|
logging.SetAllLoggers(logging.LevelInfo)
|
|
|
|
|
|
|
|
ctx := context.TODO()
|
|
|
|
|
|
|
|
cg, err := gen.NewGenerator()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// predicting the address here... may break if other assumptions change
|
2020-02-29 01:12:47 +00:00
|
|
|
taddr, err := address.NewIDAddress(1002)
|
2020-01-31 23:51:15 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2021-09-02 16:07:23 +00:00
|
|
|
sm, err := NewStateManager(
|
2022-09-27 10:21:42 +00:00
|
|
|
cg.ChainStore(), consensus.NewTipSetExecutor(filcns.RewardFunc), cg.StateManager().VMSys(), UpgradeSchedule{{
|
2021-07-16 19:17:16 +00:00
|
|
|
Network: network.Version1,
|
2020-10-03 00:09:56 +00:00
|
|
|
Height: testForkHeight,
|
2021-06-04 00:44:38 +00:00
|
|
|
Migration: func(ctx context.Context, sm *StateManager, cache MigrationCache, cb ExecMonitor,
|
2022-04-12 07:33:38 +00:00
|
|
|
root cid.Cid, height abi.ChainEpoch, ts *types.TipSet) (cid.Cid, error) {
|
2021-02-28 22:48:36 +00:00
|
|
|
cst := ipldcbor.NewCborStore(sm.ChainStore().StateBlockstore())
|
2020-01-31 23:51:15 +00:00
|
|
|
|
2020-10-01 22:02:40 +00:00
|
|
|
st, err := sm.StateTree(root)
|
|
|
|
if err != nil {
|
|
|
|
return cid.Undef, xerrors.Errorf("getting state tree: %w", err)
|
|
|
|
}
|
2020-01-31 23:51:15 +00:00
|
|
|
|
2020-10-01 22:02:40 +00:00
|
|
|
act, err := st.GetActor(taddr)
|
|
|
|
if err != nil {
|
|
|
|
return cid.Undef, err
|
|
|
|
}
|
2020-01-31 23:51:15 +00:00
|
|
|
|
2020-10-01 22:02:40 +00:00
|
|
|
var tas testActorState
|
|
|
|
if err := cst.Get(ctx, act.Head, &tas); err != nil {
|
|
|
|
return cid.Undef, xerrors.Errorf("in fork handler, failed to run get: %w", err)
|
|
|
|
}
|
2020-01-31 23:51:15 +00:00
|
|
|
|
2020-10-01 22:02:40 +00:00
|
|
|
tas.HasUpgraded = 55
|
2020-01-31 23:51:15 +00:00
|
|
|
|
2020-10-01 22:02:40 +00:00
|
|
|
ns, err := cst.Put(ctx, &tas)
|
|
|
|
if err != nil {
|
|
|
|
return cid.Undef, err
|
|
|
|
}
|
2020-01-31 23:51:15 +00:00
|
|
|
|
2020-10-01 22:02:40 +00:00
|
|
|
act.Head = ns
|
2020-01-31 23:51:15 +00:00
|
|
|
|
2020-10-01 22:02:40 +00:00
|
|
|
if err := st.SetActor(taddr, act); err != nil {
|
|
|
|
return cid.Undef, err
|
|
|
|
}
|
2020-01-31 23:51:15 +00:00
|
|
|
|
2020-10-01 22:02:40 +00:00
|
|
|
return st.Flush(ctx)
|
2023-03-12 13:33:36 +00:00
|
|
|
}}}, cg.BeaconSchedule(), datastore.NewMapDatastore(), index.DummyMsgIndex)
|
2020-10-03 00:09:56 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
2020-01-31 23:51:15 +00:00
|
|
|
}
|
|
|
|
|
2022-09-27 10:21:42 +00:00
|
|
|
inv := consensus.NewActorRegistry()
|
2022-09-21 14:56:58 +00:00
|
|
|
registry := builtin.MakeRegistryLegacy([]rtt.VMActor{testActor{}})
|
|
|
|
inv.Register(actorstypes.Version0, nil, registry)
|
2020-10-01 22:02:40 +00:00
|
|
|
|
2023-03-23 15:17:46 +00:00
|
|
|
sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.Executor, error) {
|
2022-03-15 23:40:17 +00:00
|
|
|
nvm, err := vm.NewLegacyVM(ctx, vmopt)
|
2020-01-31 23:51:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
nvm.SetInvoker(inv)
|
2023-03-23 15:17:46 +00:00
|
|
|
return &mockExecutor{nvm}, nil
|
2020-01-31 23:51:15 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
cg.SetStateManager(sm)
|
|
|
|
|
|
|
|
var msgs []*types.SignedMessage
|
|
|
|
|
2020-10-08 01:09:33 +00:00
|
|
|
enc, err := actors.SerializeParams(&init2.ExecParams{CodeCID: (testActor{}).Code()})
|
2020-01-31 23:51:15 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
m := &types.Message{
|
|
|
|
From: cg.Banker(),
|
2020-10-08 20:32:54 +00:00
|
|
|
To: _init.Address,
|
|
|
|
Method: _init.Methods.Exec,
|
2020-01-31 23:51:15 +00:00
|
|
|
Params: enc,
|
2020-07-20 17:57:06 +00:00
|
|
|
GasLimit: types.TestGasLimit,
|
2020-01-31 23:51:15 +00:00
|
|
|
}
|
2020-10-08 23:33:50 +00:00
|
|
|
sig, err := cg.Wallet().WalletSign(ctx, cg.Banker(), m.Cid().Bytes(), api.MsgMeta{})
|
2020-01-31 23:51:15 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
msgs = append(msgs, &types.SignedMessage{
|
|
|
|
Signature: *sig,
|
|
|
|
Message: *m,
|
|
|
|
})
|
|
|
|
|
|
|
|
nonce := uint64(1)
|
|
|
|
cg.GetMessages = func(cg *gen.ChainGen) ([]*types.SignedMessage, error) {
|
|
|
|
if len(msgs) > 0 {
|
|
|
|
fmt.Println("added construct method")
|
|
|
|
m := msgs
|
|
|
|
msgs = nil
|
|
|
|
return m, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
m := &types.Message{
|
|
|
|
From: cg.Banker(),
|
|
|
|
To: taddr,
|
|
|
|
Method: 2,
|
|
|
|
Params: nil,
|
|
|
|
Nonce: nonce,
|
2020-07-20 17:57:06 +00:00
|
|
|
GasLimit: types.TestGasLimit,
|
2020-01-31 23:51:15 +00:00
|
|
|
}
|
|
|
|
nonce++
|
|
|
|
|
2020-10-08 23:33:50 +00:00
|
|
|
sig, err := cg.Wallet().WalletSign(ctx, cg.Banker(), m.Cid().Bytes(), api.MsgMeta{})
|
2020-01-31 23:51:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return []*types.SignedMessage{
|
2020-04-08 19:37:04 +00:00
|
|
|
{
|
2020-01-31 23:51:15 +00:00
|
|
|
Signature: *sig,
|
|
|
|
Message: *m,
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < 50; i++ {
|
|
|
|
_, err = cg.NextTipSet()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-07 22:28:16 +00:00
|
|
|
|
|
|
|
func TestForkRefuseCall(t *testing.T) {
|
feat: Add additional test annotations (#8272)
* Annotate api,proxy_util,blockstore_badger, policy tests
* Annotate splitstore: bsbadger / markset
* Annotate splitstore feature
* Annotate union/timed blockstore tests
* Annotate openrpc, diff_adt tests
* Annotate error,drand,events tests
* Annotate predicates_test
* Fix annotations
* Annotate tscache, gen tests
* Annotate fundmanager test
* Annotate repub and selection tests
* Annotate statetree_test
* Annotate forks_test
* Annotate searchwait_test.go
* Fix duplicated @@ symbols
* Annotate chain stmgr/store tests
* Annotate more (types) tests
* More tests annotated
* Annotate conformance chaos actor tests
* Annotate more integration tests
* Annotate journal system tests
* Annotate more tests.
* Annotate gas,head buffer behaviors
* Fix markset annotations
* doc: test annotations for the markets dagstore wrapper
* Annotate miner_api test in dagstore
* Annotate more test files
* Remove bad annotations from fsrepo
* Annotate wdpost system
* Remove bad annotations
* Renamce "conformance" to "chaos_actor" tests
* doc: stm annotations for blockheader & election proof tests
* Annotate remaining "A" tests
* annotate: stm for error_test
* memrepo_test.go
* Annotate "b" file tests
* message_test.go
* doc: stm annotate for fsrepo_test
* Annotate "c" file tests
* Annotate "D" test files
* message_test.go
* doc: stm annotate for chain, node/config & client
* docs: stm annotate node_test
* Annotate u,v,wl tests
* doc: stm annotations for various test files
* Annotate "T" test files
* doc: stm annotate for proxy_util_test & policy_test
* doc: stm annotate for various tests
* doc: final few stm annotations
* Add mempool unit tests
* Add two more memPool Add tests
* Update submodules
* Add check function tests
* Add stm annotations, refactor test helper
* Annotate api,proxy_util,blockstore_badger, policy tests
* Annotate splitstore: bsbadger / markset
solving merge conflicts
* Annotate splitstore feature
* Annotate union/timed blockstore tests
* Annotate openrpc, diff_adt tests
* Annotate error,drand,events tests
* Annotate predicates_test
* Fix annotations
* Annotate tscache, gen tests
* Annotate fundmanager test
* Annotate statetree_test
* Annotate forks_test
* Annotate searchwait_test.go
* Fix duplicated @@ symbols
* Annotate chain stmgr/store tests
* Annotate more (types) tests
* More tests annotated
* Annotate conformance chaos actor tests
* Annotate more integration tests
* Annotate journal system tests
* Annotate more tests.
* Annotate gas,head buffer behaviors
solve merge conflict
* Fix markset annotations
* Annotate miner_api test in dagstore
* Annotate more test files
* doc: test annotations for the markets dagstore wrapper
* Annotate wdpost system
* Renamce "conformance" to "chaos_actor" tests
* Annotate remaining "A" tests
* doc: stm annotations for blockheader & election proof tests
* annotate: stm for error_test
* Annotate "b" file tests
* memrepo_test.go
* Annotate "c" file tests
* message_test.go
* Annotate "D" test files
* doc: stm annotate for fsrepo_test
* Annotate u,v,wl tests
* message_test.go
* doc: stm annotate for chain, node/config & client
* docs: stm annotate node_test
* Annotate "T" test files
* doc: stm annotations for various test files
* Add mempool unit tests
solve merge conflict
* doc: stm annotate for proxy_util_test & policy_test
* doc: stm annotate for various tests
* doc: final few stm annotations
* Add two more memPool Add tests
* Update submodules
* Add check function tests
solve conflict
* Add stm annotations, refactor test helper
solve merge conflict
* Change CLI test kinds to "unit"
* Fix double merged test
* Fix ccupgrade_test merge
* Fix lint issues
* Add stm annotation to types_Test
* Test vectors submodule
* Add file annotation to burn_test
Co-authored-by: Nikola Divic <divicnikola@gmail.com>
Co-authored-by: TheMenko <themenkoprojects@gmail.com>
2022-03-16 17:37:34 +00:00
|
|
|
//stm: @CHAIN_GEN_NEXT_TIPSET_001, @CHAIN_GEN_NEXT_TIPSET_FROM_MINERS_001
|
|
|
|
//stm: @CHAIN_STATE_RESOLVE_TO_KEY_ADDR_001, @CHAIN_STATE_SET_VM_CONSTRUCTOR_001, @CHAIN_STATE_CALL_001
|
2020-10-07 22:28:16 +00:00
|
|
|
logging.SetAllLoggers(logging.LevelInfo)
|
|
|
|
|
2021-08-27 00:23:04 +00:00
|
|
|
for after := 0; after < 3; after++ {
|
|
|
|
for before := 0; before < 3; before++ {
|
|
|
|
// Makes the lints happy...
|
|
|
|
after := after
|
|
|
|
before := before
|
|
|
|
t.Run(fmt.Sprintf("after:%d,before:%d", after, before), func(t *testing.T) {
|
|
|
|
testForkRefuseCall(t, before, after)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
func testForkRefuseCall(t *testing.T, nullsBefore, nullsAfter int) {
|
2020-10-07 22:28:16 +00:00
|
|
|
ctx := context.TODO()
|
|
|
|
|
|
|
|
cg, err := gen.NewGenerator()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2021-08-27 00:23:04 +00:00
|
|
|
var migrationCount int
|
2021-09-02 16:07:23 +00:00
|
|
|
sm, err := NewStateManager(
|
2022-09-27 10:21:42 +00:00
|
|
|
cg.ChainStore(), consensus.NewTipSetExecutor(filcns.RewardFunc), cg.StateManager().VMSys(), UpgradeSchedule{{
|
2021-07-16 19:17:16 +00:00
|
|
|
Network: network.Version1,
|
2020-10-07 23:14:11 +00:00
|
|
|
Expensive: true,
|
|
|
|
Height: testForkHeight,
|
2021-06-04 00:44:38 +00:00
|
|
|
Migration: func(ctx context.Context, sm *StateManager, cache MigrationCache, cb ExecMonitor,
|
2022-04-12 07:33:38 +00:00
|
|
|
root cid.Cid, height abi.ChainEpoch, ts *types.TipSet) (cid.Cid, error) {
|
2021-08-27 00:23:04 +00:00
|
|
|
migrationCount++
|
2020-10-07 22:28:16 +00:00
|
|
|
return root, nil
|
2023-03-12 13:33:36 +00:00
|
|
|
}}}, cg.BeaconSchedule(), datastore.NewMapDatastore(), index.DummyMsgIndex)
|
2020-10-07 22:28:16 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2022-09-27 10:21:42 +00:00
|
|
|
inv := consensus.NewActorRegistry()
|
2022-09-21 14:56:58 +00:00
|
|
|
registry := builtin.MakeRegistryLegacy([]rtt.VMActor{testActor{}})
|
|
|
|
inv.Register(actorstypes.Version0, nil, registry)
|
2020-10-07 22:28:16 +00:00
|
|
|
|
2023-03-23 15:17:46 +00:00
|
|
|
sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.Executor, error) {
|
2022-03-15 23:40:17 +00:00
|
|
|
nvm, err := vm.NewLegacyVM(ctx, vmopt)
|
2020-10-07 22:28:16 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
nvm.SetInvoker(inv)
|
2023-03-23 15:17:46 +00:00
|
|
|
return &mockExecutor{nvm}, nil
|
2020-10-07 22:28:16 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
cg.SetStateManager(sm)
|
|
|
|
|
2020-10-08 01:09:33 +00:00
|
|
|
enc, err := actors.SerializeParams(&init2.ExecParams{CodeCID: (testActor{}).Code()})
|
2020-10-07 22:28:16 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
m := &types.Message{
|
|
|
|
From: cg.Banker(),
|
2020-10-08 20:32:54 +00:00
|
|
|
To: _init.Address,
|
|
|
|
Method: _init.Methods.Exec,
|
2020-10-07 22:28:16 +00:00
|
|
|
Params: enc,
|
|
|
|
GasLimit: types.TestGasLimit,
|
|
|
|
Value: types.NewInt(0),
|
|
|
|
GasPremium: types.NewInt(0),
|
|
|
|
GasFeeCap: types.NewInt(0),
|
|
|
|
}
|
|
|
|
|
2021-08-27 00:23:04 +00:00
|
|
|
nullStart := abi.ChainEpoch(testForkHeight - nullsBefore)
|
|
|
|
nullLength := abi.ChainEpoch(nullsBefore + nullsAfter)
|
|
|
|
|
2021-08-30 23:20:23 +00:00
|
|
|
for i := 0; i < testForkHeight*2; i++ {
|
2021-08-27 00:23:04 +00:00
|
|
|
pts := cg.CurTipset.TipSet()
|
|
|
|
skip := abi.ChainEpoch(0)
|
|
|
|
if pts.Height() == nullStart {
|
|
|
|
skip = nullLength
|
|
|
|
}
|
|
|
|
ts, err := cg.NextTipSetFromMiners(pts, cg.Miners, skip)
|
2020-10-07 22:28:16 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2021-07-15 00:41:24 +00:00
|
|
|
parentHeight := pts.Height()
|
|
|
|
currentHeight := ts.TipSet.TipSet().Height()
|
|
|
|
|
2022-11-16 23:19:59 +00:00
|
|
|
// CallWithGas calls on top of the given tipset.
|
2023-03-23 22:27:01 +00:00
|
|
|
ret, err := sm.CallWithGas(ctx, m, nil, ts.TipSet.TipSet(), true)
|
2021-07-15 00:41:24 +00:00
|
|
|
if parentHeight <= testForkHeight && currentHeight >= testForkHeight {
|
2020-10-07 22:28:16 +00:00
|
|
|
// If I had a fork, or I _will_ have a fork, it should fail.
|
2020-10-07 23:14:11 +00:00
|
|
|
require.Equal(t, ErrExpensiveFork, err)
|
2021-07-15 00:41:24 +00:00
|
|
|
} else {
|
2020-10-07 22:28:16 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, ret.MsgRct.ExitCode.IsSuccess())
|
|
|
|
}
|
2021-07-15 00:41:24 +00:00
|
|
|
|
|
|
|
// Call always applies the message to the "next block" after the tipset's parent state.
|
2020-10-07 22:28:16 +00:00
|
|
|
ret, err = sm.Call(ctx, m, ts.TipSet.TipSet())
|
2022-11-16 23:19:59 +00:00
|
|
|
if parentHeight <= testForkHeight && currentHeight >= testForkHeight {
|
2020-10-07 23:14:11 +00:00
|
|
|
require.Equal(t, ErrExpensiveFork, err)
|
2021-07-15 00:41:24 +00:00
|
|
|
} else {
|
2020-10-07 22:28:16 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, ret.MsgRct.ExitCode.IsSuccess())
|
|
|
|
}
|
2021-08-27 00:23:04 +00:00
|
|
|
|
|
|
|
// Calls without a tipset should walk back to the last non-fork tipset.
|
|
|
|
// We _verify_ that the migration wasn't run multiple times at the end of the
|
|
|
|
// test.
|
2023-03-23 22:27:01 +00:00
|
|
|
ret, err = sm.CallWithGas(ctx, m, nil, nil, true)
|
2021-08-27 00:23:04 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, ret.MsgRct.ExitCode.IsSuccess())
|
|
|
|
|
|
|
|
ret, err = sm.Call(ctx, m, nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, ret.MsgRct.ExitCode.IsSuccess())
|
2020-10-07 22:28:16 +00:00
|
|
|
}
|
2021-08-27 00:23:04 +00:00
|
|
|
// Make sure we didn't execute the migration multiple times.
|
|
|
|
require.Equal(t, migrationCount, 1)
|
2020-10-07 22:28:16 +00:00
|
|
|
}
|
2021-01-27 02:45:50 +00:00
|
|
|
|
|
|
|
func TestForkPreMigration(t *testing.T) {
|
feat: Add additional test annotations (#8272)
* Annotate api,proxy_util,blockstore_badger, policy tests
* Annotate splitstore: bsbadger / markset
* Annotate splitstore feature
* Annotate union/timed blockstore tests
* Annotate openrpc, diff_adt tests
* Annotate error,drand,events tests
* Annotate predicates_test
* Fix annotations
* Annotate tscache, gen tests
* Annotate fundmanager test
* Annotate repub and selection tests
* Annotate statetree_test
* Annotate forks_test
* Annotate searchwait_test.go
* Fix duplicated @@ symbols
* Annotate chain stmgr/store tests
* Annotate more (types) tests
* More tests annotated
* Annotate conformance chaos actor tests
* Annotate more integration tests
* Annotate journal system tests
* Annotate more tests.
* Annotate gas,head buffer behaviors
* Fix markset annotations
* doc: test annotations for the markets dagstore wrapper
* Annotate miner_api test in dagstore
* Annotate more test files
* Remove bad annotations from fsrepo
* Annotate wdpost system
* Remove bad annotations
* Renamce "conformance" to "chaos_actor" tests
* doc: stm annotations for blockheader & election proof tests
* Annotate remaining "A" tests
* annotate: stm for error_test
* memrepo_test.go
* Annotate "b" file tests
* message_test.go
* doc: stm annotate for fsrepo_test
* Annotate "c" file tests
* Annotate "D" test files
* message_test.go
* doc: stm annotate for chain, node/config & client
* docs: stm annotate node_test
* Annotate u,v,wl tests
* doc: stm annotations for various test files
* Annotate "T" test files
* doc: stm annotate for proxy_util_test & policy_test
* doc: stm annotate for various tests
* doc: final few stm annotations
* Add mempool unit tests
* Add two more memPool Add tests
* Update submodules
* Add check function tests
* Add stm annotations, refactor test helper
* Annotate api,proxy_util,blockstore_badger, policy tests
* Annotate splitstore: bsbadger / markset
solving merge conflicts
* Annotate splitstore feature
* Annotate union/timed blockstore tests
* Annotate openrpc, diff_adt tests
* Annotate error,drand,events tests
* Annotate predicates_test
* Fix annotations
* Annotate tscache, gen tests
* Annotate fundmanager test
* Annotate statetree_test
* Annotate forks_test
* Annotate searchwait_test.go
* Fix duplicated @@ symbols
* Annotate chain stmgr/store tests
* Annotate more (types) tests
* More tests annotated
* Annotate conformance chaos actor tests
* Annotate more integration tests
* Annotate journal system tests
* Annotate more tests.
* Annotate gas,head buffer behaviors
solve merge conflict
* Fix markset annotations
* Annotate miner_api test in dagstore
* Annotate more test files
* doc: test annotations for the markets dagstore wrapper
* Annotate wdpost system
* Renamce "conformance" to "chaos_actor" tests
* Annotate remaining "A" tests
* doc: stm annotations for blockheader & election proof tests
* annotate: stm for error_test
* Annotate "b" file tests
* memrepo_test.go
* Annotate "c" file tests
* message_test.go
* Annotate "D" test files
* doc: stm annotate for fsrepo_test
* Annotate u,v,wl tests
* message_test.go
* doc: stm annotate for chain, node/config & client
* docs: stm annotate node_test
* Annotate "T" test files
* doc: stm annotations for various test files
* Add mempool unit tests
solve merge conflict
* doc: stm annotate for proxy_util_test & policy_test
* doc: stm annotate for various tests
* doc: final few stm annotations
* Add two more memPool Add tests
* Update submodules
* Add check function tests
solve conflict
* Add stm annotations, refactor test helper
solve merge conflict
* Change CLI test kinds to "unit"
* Fix double merged test
* Fix ccupgrade_test merge
* Fix lint issues
* Add stm annotation to types_Test
* Test vectors submodule
* Add file annotation to burn_test
Co-authored-by: Nikola Divic <divicnikola@gmail.com>
Co-authored-by: TheMenko <themenkoprojects@gmail.com>
2022-03-16 17:37:34 +00:00
|
|
|
//stm: @CHAIN_GEN_NEXT_TIPSET_001,
|
|
|
|
//stm: @CHAIN_STATE_RESOLVE_TO_KEY_ADDR_001, @CHAIN_STATE_SET_VM_CONSTRUCTOR_001
|
2021-01-27 02:45:50 +00:00
|
|
|
logging.SetAllLoggers(logging.LevelInfo)
|
|
|
|
|
|
|
|
cg, err := gen.NewGenerator()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fooCid, err := abi.CidBuilder.Sum([]byte("foo"))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
barCid, err := abi.CidBuilder.Sum([]byte("bar"))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
failCid, err := abi.CidBuilder.Sum([]byte("fail"))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
var wait20 sync.WaitGroup
|
|
|
|
wait20.Add(3)
|
|
|
|
|
|
|
|
wasCanceled := make(chan struct{})
|
|
|
|
|
|
|
|
checkCache := func(t *testing.T, cache MigrationCache) {
|
|
|
|
found, value, err := cache.Read("foo")
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, found)
|
|
|
|
require.Equal(t, fooCid, value)
|
|
|
|
|
|
|
|
found, value, err = cache.Read("bar")
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, found)
|
|
|
|
require.Equal(t, barCid, value)
|
|
|
|
|
|
|
|
found, _, err = cache.Read("fail")
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.False(t, found)
|
|
|
|
}
|
|
|
|
|
2021-01-28 00:12:08 +00:00
|
|
|
counter := make(chan struct{}, 10)
|
|
|
|
|
2021-09-02 16:07:23 +00:00
|
|
|
sm, err := NewStateManager(
|
2022-09-27 10:21:42 +00:00
|
|
|
cg.ChainStore(), consensus.NewTipSetExecutor(filcns.RewardFunc), cg.StateManager().VMSys(), UpgradeSchedule{{
|
2021-07-16 19:17:16 +00:00
|
|
|
Network: network.Version1,
|
2021-01-27 02:45:50 +00:00
|
|
|
Height: testForkHeight,
|
2021-06-04 00:44:38 +00:00
|
|
|
Migration: func(ctx context.Context, sm *StateManager, cache MigrationCache, cb ExecMonitor,
|
2022-04-12 07:33:38 +00:00
|
|
|
root cid.Cid, height abi.ChainEpoch, ts *types.TipSet) (cid.Cid, error) {
|
2021-01-27 02:45:50 +00:00
|
|
|
|
|
|
|
// Make sure the test that should be canceled, is canceled.
|
|
|
|
select {
|
|
|
|
case <-wasCanceled:
|
|
|
|
case <-ctx.Done():
|
|
|
|
return cid.Undef, ctx.Err()
|
|
|
|
}
|
|
|
|
|
|
|
|
// the cache should be setup correctly.
|
|
|
|
checkCache(t, cache)
|
|
|
|
|
2021-01-28 00:12:08 +00:00
|
|
|
counter <- struct{}{}
|
|
|
|
|
2021-01-27 02:45:50 +00:00
|
|
|
return root, nil
|
|
|
|
},
|
|
|
|
PreMigrations: []PreMigration{{
|
2021-01-27 23:58:51 +00:00
|
|
|
StartWithin: 20,
|
2021-01-27 02:45:50 +00:00
|
|
|
PreMigration: func(ctx context.Context, _ *StateManager, cache MigrationCache,
|
2022-04-12 07:33:38 +00:00
|
|
|
_ cid.Cid, _ abi.ChainEpoch, _ *types.TipSet) error {
|
2021-01-27 02:45:50 +00:00
|
|
|
wait20.Done()
|
|
|
|
wait20.Wait()
|
|
|
|
|
|
|
|
err := cache.Write("foo", fooCid)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-01-28 00:12:08 +00:00
|
|
|
counter <- struct{}{}
|
|
|
|
|
2021-01-27 02:45:50 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}, {
|
2021-01-27 23:58:51 +00:00
|
|
|
StartWithin: 20,
|
2021-01-27 02:45:50 +00:00
|
|
|
PreMigration: func(ctx context.Context, _ *StateManager, cache MigrationCache,
|
2022-04-12 07:33:38 +00:00
|
|
|
_ cid.Cid, _ abi.ChainEpoch, _ *types.TipSet) error {
|
2021-01-27 02:45:50 +00:00
|
|
|
wait20.Done()
|
|
|
|
wait20.Wait()
|
|
|
|
|
|
|
|
err := cache.Write("bar", barCid)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-01-28 00:12:08 +00:00
|
|
|
counter <- struct{}{}
|
|
|
|
|
2021-01-27 02:45:50 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}, {
|
2021-01-27 23:58:51 +00:00
|
|
|
StartWithin: 20,
|
2021-01-27 02:45:50 +00:00
|
|
|
PreMigration: func(ctx context.Context, _ *StateManager, cache MigrationCache,
|
2022-04-12 07:33:38 +00:00
|
|
|
_ cid.Cid, _ abi.ChainEpoch, _ *types.TipSet) error {
|
2021-01-27 02:45:50 +00:00
|
|
|
wait20.Done()
|
|
|
|
wait20.Wait()
|
|
|
|
|
|
|
|
err := cache.Write("fail", failCid)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-01-28 00:12:08 +00:00
|
|
|
counter <- struct{}{}
|
|
|
|
|
2021-01-27 02:45:50 +00:00
|
|
|
// Fail this migration. The cached entry should not be persisted.
|
|
|
|
return fmt.Errorf("failed")
|
|
|
|
},
|
|
|
|
}, {
|
2021-01-27 23:58:51 +00:00
|
|
|
StartWithin: 15,
|
|
|
|
StopWithin: 5,
|
2021-01-27 02:45:50 +00:00
|
|
|
PreMigration: func(ctx context.Context, _ *StateManager, cache MigrationCache,
|
2022-04-12 07:33:38 +00:00
|
|
|
_ cid.Cid, _ abi.ChainEpoch, _ *types.TipSet) error {
|
2021-01-27 02:45:50 +00:00
|
|
|
|
2021-01-27 20:54:56 +00:00
|
|
|
<-ctx.Done()
|
|
|
|
close(wasCanceled)
|
2021-01-27 02:45:50 +00:00
|
|
|
|
2021-01-28 00:12:08 +00:00
|
|
|
counter <- struct{}{}
|
|
|
|
|
2021-01-27 02:45:50 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}, {
|
2021-01-27 23:58:51 +00:00
|
|
|
StartWithin: 10,
|
2021-01-27 02:45:50 +00:00
|
|
|
PreMigration: func(ctx context.Context, _ *StateManager, cache MigrationCache,
|
2022-04-12 07:33:38 +00:00
|
|
|
_ cid.Cid, _ abi.ChainEpoch, _ *types.TipSet) error {
|
2021-01-27 02:45:50 +00:00
|
|
|
|
2021-01-27 20:54:56 +00:00
|
|
|
checkCache(t, cache)
|
2021-01-27 02:45:50 +00:00
|
|
|
|
2021-01-28 00:12:08 +00:00
|
|
|
counter <- struct{}{}
|
|
|
|
|
2021-01-27 02:45:50 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}}},
|
2023-03-12 13:33:36 +00:00
|
|
|
}, cg.BeaconSchedule(), datastore.NewMapDatastore(), index.DummyMsgIndex)
|
2021-01-27 02:45:50 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
require.NoError(t, sm.Start(context.Background()))
|
|
|
|
defer func() {
|
|
|
|
require.NoError(t, sm.Stop(context.Background()))
|
|
|
|
}()
|
|
|
|
|
2022-09-27 10:21:42 +00:00
|
|
|
inv := consensus.NewActorRegistry()
|
2022-09-21 14:56:58 +00:00
|
|
|
registry := builtin.MakeRegistryLegacy([]rtt.VMActor{testActor{}})
|
|
|
|
inv.Register(actorstypes.Version0, nil, registry)
|
2021-01-27 02:45:50 +00:00
|
|
|
|
2023-03-23 15:17:46 +00:00
|
|
|
sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.Executor, error) {
|
2022-03-15 23:40:17 +00:00
|
|
|
nvm, err := vm.NewLegacyVM(ctx, vmopt)
|
2021-01-27 02:45:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
nvm.SetInvoker(inv)
|
2023-03-23 15:17:46 +00:00
|
|
|
return &mockExecutor{nvm}, nil
|
2021-01-27 02:45:50 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
cg.SetStateManager(sm)
|
|
|
|
|
|
|
|
for i := 0; i < 50; i++ {
|
|
|
|
_, err := cg.NextTipSet()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
2021-01-28 00:12:08 +00:00
|
|
|
// We have 5 pre-migration steps, and the migration. They should all have written something
|
|
|
|
// to this channel.
|
|
|
|
require.Equal(t, 6, len(counter))
|
2021-01-27 02:45:50 +00:00
|
|
|
}
|
2023-02-15 21:24:21 +00:00
|
|
|
|
|
|
|
func TestDisablePreMigration(t *testing.T) {
|
|
|
|
logging.SetAllLoggers(logging.LevelInfo)
|
|
|
|
|
|
|
|
cg, err := gen.NewGenerator()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = os.Setenv(EnvDisablePreMigrations, "1")
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
err := os.Unsetenv(EnvDisablePreMigrations)
|
|
|
|
require.NoError(t, err)
|
|
|
|
}()
|
|
|
|
|
|
|
|
counter := make(chan struct{}, 10)
|
|
|
|
|
|
|
|
sm, err := NewStateManager(
|
|
|
|
cg.ChainStore(),
|
|
|
|
consensus.NewTipSetExecutor(filcns.RewardFunc),
|
|
|
|
cg.StateManager().VMSys(),
|
|
|
|
UpgradeSchedule{{
|
|
|
|
Network: network.Version1,
|
|
|
|
Height: testForkHeight,
|
|
|
|
Migration: func(_ context.Context, _ *StateManager, _ MigrationCache, _ ExecMonitor,
|
|
|
|
root cid.Cid, _ abi.ChainEpoch, _ *types.TipSet) (cid.Cid, error) {
|
|
|
|
|
|
|
|
counter <- struct{}{}
|
|
|
|
|
|
|
|
return root, nil
|
|
|
|
},
|
|
|
|
PreMigrations: []PreMigration{{
|
|
|
|
StartWithin: 20,
|
|
|
|
PreMigration: func(ctx context.Context, _ *StateManager, _ MigrationCache,
|
|
|
|
_ cid.Cid, _ abi.ChainEpoch, _ *types.TipSet) error {
|
|
|
|
panic("should be skipped")
|
|
|
|
},
|
|
|
|
}}},
|
|
|
|
},
|
|
|
|
cg.BeaconSchedule(),
|
2023-02-27 17:27:48 +00:00
|
|
|
datastore.NewMapDatastore(),
|
2023-03-12 13:33:36 +00:00
|
|
|
index.DummyMsgIndex,
|
2023-02-15 21:24:21 +00:00
|
|
|
)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, sm.Start(context.Background()))
|
|
|
|
defer func() {
|
|
|
|
require.NoError(t, sm.Stop(context.Background()))
|
|
|
|
}()
|
|
|
|
|
|
|
|
inv := consensus.NewActorRegistry()
|
|
|
|
registry := builtin.MakeRegistryLegacy([]rtt.VMActor{testActor{}})
|
|
|
|
inv.Register(actorstypes.Version0, nil, registry)
|
|
|
|
|
2023-03-23 15:17:46 +00:00
|
|
|
sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.Executor, error) {
|
2023-02-15 21:24:21 +00:00
|
|
|
nvm, err := vm.NewLegacyVM(ctx, vmopt)
|
|
|
|
require.NoError(t, err)
|
|
|
|
nvm.SetInvoker(inv)
|
2023-03-23 15:17:46 +00:00
|
|
|
return &mockExecutor{nvm}, nil
|
2023-02-15 21:24:21 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
cg.SetStateManager(sm)
|
|
|
|
|
|
|
|
for i := 0; i < 50; i++ {
|
|
|
|
_, err := cg.NextTipSet()
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
require.Equal(t, 1, len(counter))
|
|
|
|
}
|
2023-02-27 17:27:48 +00:00
|
|
|
|
|
|
|
func TestMigrtionCache(t *testing.T) {
|
|
|
|
logging.SetAllLoggers(logging.LevelInfo)
|
|
|
|
|
|
|
|
cg, err := gen.NewGenerator()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
counter := make(chan struct{}, 10)
|
|
|
|
metadataDs := datastore.NewMapDatastore()
|
|
|
|
|
|
|
|
sm, err := NewStateManager(
|
|
|
|
cg.ChainStore(),
|
|
|
|
consensus.NewTipSetExecutor(filcns.RewardFunc),
|
|
|
|
cg.StateManager().VMSys(),
|
|
|
|
UpgradeSchedule{{
|
|
|
|
Network: network.Version1,
|
|
|
|
Height: testForkHeight,
|
|
|
|
Migration: func(_ context.Context, _ *StateManager, _ MigrationCache, _ ExecMonitor,
|
|
|
|
root cid.Cid, _ abi.ChainEpoch, _ *types.TipSet) (cid.Cid, error) {
|
|
|
|
|
|
|
|
counter <- struct{}{}
|
|
|
|
|
|
|
|
return root, nil
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
cg.BeaconSchedule(),
|
|
|
|
metadataDs,
|
2023-03-12 13:33:36 +00:00
|
|
|
index.DummyMsgIndex,
|
2023-02-27 17:27:48 +00:00
|
|
|
)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, sm.Start(context.Background()))
|
|
|
|
defer func() {
|
|
|
|
require.NoError(t, sm.Stop(context.Background()))
|
|
|
|
}()
|
|
|
|
|
|
|
|
inv := consensus.NewActorRegistry()
|
|
|
|
registry := builtin.MakeRegistryLegacy([]rtt.VMActor{testActor{}})
|
|
|
|
inv.Register(actorstypes.Version0, nil, registry)
|
|
|
|
|
2023-03-23 15:17:46 +00:00
|
|
|
sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.Executor, error) {
|
2023-02-27 17:27:48 +00:00
|
|
|
nvm, err := vm.NewLegacyVM(ctx, vmopt)
|
|
|
|
require.NoError(t, err)
|
|
|
|
nvm.SetInvoker(inv)
|
2023-03-23 15:17:46 +00:00
|
|
|
return &mockExecutor{nvm}, nil
|
2023-02-27 17:27:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
cg.SetStateManager(sm)
|
|
|
|
|
|
|
|
for i := 0; i < 50; i++ {
|
|
|
|
_, err := cg.NextTipSet()
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
ts, err := cg.ChainStore().GetTipsetByHeight(context.Background(), testForkHeight, nil, false)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
root, _, err := stmgr.ComputeState(context.Background(), sm, testForkHeight+1, []*types.Message{}, ts)
|
|
|
|
require.NoError(t, err)
|
|
|
|
t.Log(root)
|
|
|
|
|
|
|
|
require.Equal(t, 1, len(counter))
|
|
|
|
|
|
|
|
{
|
|
|
|
sm, err := NewStateManager(
|
|
|
|
cg.ChainStore(),
|
|
|
|
consensus.NewTipSetExecutor(filcns.RewardFunc),
|
|
|
|
cg.StateManager().VMSys(),
|
|
|
|
UpgradeSchedule{{
|
|
|
|
Network: network.Version1,
|
|
|
|
Height: testForkHeight,
|
|
|
|
Migration: func(_ context.Context, _ *StateManager, _ MigrationCache, _ ExecMonitor,
|
|
|
|
root cid.Cid, _ abi.ChainEpoch, _ *types.TipSet) (cid.Cid, error) {
|
|
|
|
|
|
|
|
counter <- struct{}{}
|
|
|
|
|
|
|
|
return root, nil
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
cg.BeaconSchedule(),
|
|
|
|
metadataDs,
|
2023-03-12 13:33:36 +00:00
|
|
|
index.DummyMsgIndex,
|
2023-02-27 17:27:48 +00:00
|
|
|
)
|
|
|
|
require.NoError(t, err)
|
2023-03-23 15:17:46 +00:00
|
|
|
sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.Executor, error) {
|
2023-02-27 17:27:48 +00:00
|
|
|
nvm, err := vm.NewLegacyVM(ctx, vmopt)
|
|
|
|
require.NoError(t, err)
|
|
|
|
nvm.SetInvoker(inv)
|
2023-03-23 15:17:46 +00:00
|
|
|
return &mockExecutor{nvm}, nil
|
2023-02-27 17:27:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
base, _, err := sm.ExecutionTrace(ctx, ts)
|
|
|
|
require.NoError(t, err)
|
|
|
|
_, err = sm.HandleStateForks(context.Background(), base, ts.Height(), nil, ts)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// Should not have increased as we should be using the cached results in the metadataDs
|
|
|
|
require.Equal(t, 1, len(counter))
|
|
|
|
}
|
|
|
|
}
|