From ba3b32cfe762e207d903c71644ce8fdaaff094e4 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Fri, 15 Jan 2021 23:12:31 -0500 Subject: [PATCH 01/58] Pull in actors v3 --- chain/actors/adt/adt.go | 17 +++++++++++++---- chain/actors/builtin/verifreg/util.go | 7 +++++-- chain/actors/version.go | 3 +++ chain/state/statetree.go | 7 ++++++- chain/stmgr/stmgr.go | 3 ++- go.mod | 5 +++-- go.sum | 12 ++++++++++-- 7 files changed, 42 insertions(+), 12 deletions(-) diff --git a/chain/actors/adt/adt.go b/chain/actors/adt/adt.go index 6a454ac26..7a3007fa8 100644 --- a/chain/actors/adt/adt.go +++ b/chain/actors/adt/adt.go @@ -12,6 +12,7 @@ import ( adt0 "github.com/filecoin-project/specs-actors/actors/util/adt" adt2 "github.com/filecoin-project/specs-actors/v2/actors/util/adt" + adt3 "github.com/filecoin-project/specs-actors/v3/actors/util/adt" ) type Map interface { @@ -24,22 +25,26 @@ type Map interface { ForEach(v cbor.Unmarshaler, fn func(key string) error) error } -func AsMap(store Store, root cid.Cid, version actors.Version) (Map, error) { +func AsMap(store Store, root cid.Cid, version actors.Version, v3bitwidth int) (Map, error) { switch version { case actors.Version0: return adt0.AsMap(store, root) case actors.Version2: return adt2.AsMap(store, root) + case actors.Version3: + return adt3.AsMap(store, root, v3bitwidth) } return nil, xerrors.Errorf("unknown network version: %d", version) } -func NewMap(store Store, version actors.Version) (Map, error) { +func NewMap(store Store, version actors.Version, bitwidth int) (Map, error) { switch version { case actors.Version0: return adt0.MakeEmptyMap(store), nil case actors.Version2: return adt2.MakeEmptyMap(store), nil + case actors.Version3: + return adt3.MakeEmptyMap(store, bitwidth), nil } return nil, xerrors.Errorf("unknown network version: %d", version) } @@ -55,22 +60,26 @@ type Array interface { ForEach(v cbor.Unmarshaler, fn func(idx int64) error) error } -func AsArray(store Store, root cid.Cid, version network.Version) (Array, error) { +func AsArray(store Store, root cid.Cid, version network.Version, bitwidth int) (Array, error) { switch actors.VersionForNetwork(version) { case actors.Version0: return adt0.AsArray(store, root) case actors.Version2: return adt2.AsArray(store, root) + case actors.Version3: + return adt3.AsArray(store, root, bitwidth) } return nil, xerrors.Errorf("unknown network version: %d", version) } -func NewArray(store Store, version actors.Version) (Array, error) { +func NewArray(store Store, version actors.Version, bitwidth int) (Array, error) { switch version { case actors.Version0: return adt0.MakeEmptyArray(store), nil case actors.Version2: return adt2.MakeEmptyArray(store), nil + case actors.Version3: + return adt3.MakeEmptyArray(store, bitwidth) } return nil, xerrors.Errorf("unknown network version: %d", version) } diff --git a/chain/actors/builtin/verifreg/util.go b/chain/actors/builtin/verifreg/util.go index 4136c0c30..b7768439c 100644 --- a/chain/actors/builtin/verifreg/util.go +++ b/chain/actors/builtin/verifreg/util.go @@ -6,16 +6,18 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/adt" + builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" "github.com/ipfs/go-cid" "golang.org/x/xerrors" ) +// Assumes that the bitwidth for v3 HAMTs is the DefaultHamtBitwidth func getDataCap(store adt.Store, ver actors.Version, root cid.Cid, addr address.Address) (bool, abi.StoragePower, error) { if addr.Protocol() != address.ID { return false, big.Zero(), xerrors.Errorf("can only look up ID addresses") } - vh, err := adt.AsMap(store, root, ver) + vh, err := adt.AsMap(store, root, ver, builtin3.DefaultHamtBitwidth) if err != nil { return false, big.Zero(), xerrors.Errorf("loading verifreg: %w", err) } @@ -30,8 +32,9 @@ func getDataCap(store adt.Store, ver actors.Version, root cid.Cid, addr address. return true, dcap, nil } +// Assumes that the bitwidth for v3 HAMTs is the DefaultHamtBitwidth func forEachCap(store adt.Store, ver actors.Version, root cid.Cid, cb func(addr address.Address, dcap abi.StoragePower) error) error { - vh, err := adt.AsMap(store, root, ver) + vh, err := adt.AsMap(store, root, ver, builtin3.DefaultHamtBitwidth) if err != nil { return xerrors.Errorf("loading verified clients: %w", err) } diff --git a/chain/actors/version.go b/chain/actors/version.go index 1d9f1f8a2..763c5a42c 100644 --- a/chain/actors/version.go +++ b/chain/actors/version.go @@ -11,6 +11,7 @@ type Version int const ( Version0 Version = 0 Version2 Version = 2 + Version3 Version = 3 ) // Converts a network version into an actors adt version. @@ -20,6 +21,8 @@ func VersionForNetwork(version network.Version) Version { return Version0 case network.Version4, network.Version5, network.Version6, network.Version7, network.Version8, network.Version9: return Version2 + case network.Version10: + return Version3 default: panic(fmt.Sprintf("unsupported network version %d", version)) } diff --git a/chain/state/statetree.go b/chain/state/statetree.go index 7fa55b31c..d8cdca73a 100644 --- a/chain/state/statetree.go +++ b/chain/state/statetree.go @@ -5,6 +5,8 @@ import ( "context" "fmt" + builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" + "github.com/ipfs/go-cid" cbor "github.com/ipfs/go-ipld-cbor" logging "github.com/ipfs/go-log/v2" @@ -169,7 +171,8 @@ func NewStateTree(cst cbor.IpldStore, ver types.StateTreeVersion) (*StateTree, e default: return nil, xerrors.Errorf("unsupported state tree version: %d", ver) } - root, err := adt.NewMap(adt.WrapStore(context.TODO(), cst), adtForSTVersion(ver)) + // TODO: Confirm this is correct + root, err := adt.NewMap(adt.WrapStore(context.TODO(), cst), adtForSTVersion(ver), builtin3.DefaultHamtBitwidth) if err != nil { return nil, err } @@ -200,6 +203,8 @@ func LoadStateTree(cst cbor.IpldStore, c cid.Cid) (*StateTree, error) { nd, err := adt.AsMap( adt.WrapStore(context.TODO(), cst), root.Actors, adtForSTVersion(root.Version), + // TODO: Confirm this is correct + builtin3.DefaultHamtBitwidth, ) if err != nil { log.Errorf("loading hamt node %s failed: %s", c, err) diff --git a/chain/stmgr/stmgr.go b/chain/stmgr/stmgr.go index 5d9f35975..8a6315deb 100644 --- a/chain/stmgr/stmgr.go +++ b/chain/stmgr/stmgr.go @@ -42,6 +42,7 @@ import ( ) const LookbackNoLimit = abi.ChainEpoch(-1) +const ReceiptAmtBitwidth = 3 var log = logging.Logger("statemgr") @@ -385,7 +386,7 @@ func (sm *StateManager) ApplyBlocks(ctx context.Context, parentEpoch abi.ChainEp } // XXX: Is the height correct? Or should it be epoch-1? - rectarr, err := adt.NewArray(sm.cs.Store(ctx), actors.VersionForNetwork(sm.GetNtwkVersion(ctx, epoch))) + rectarr, err := adt.NewArray(sm.cs.Store(ctx), actors.VersionForNetwork(sm.GetNtwkVersion(ctx, epoch)), ReceiptAmtBitwidth) if err != nil { return cid.Undef, cid.Undef, xerrors.Errorf("failed to create receipts amt: %w", err) } diff --git a/go.mod b/go.mod index 0810d7e7e..62199668d 100644 --- a/go.mod +++ b/go.mod @@ -38,12 +38,13 @@ require ( github.com/filecoin-project/go-multistore v0.0.3 github.com/filecoin-project/go-padreader v0.0.0-20200903213702-ed5fae088b20 github.com/filecoin-project/go-paramfetch v0.0.2-0.20200701152213-3e0f0afdc261 - github.com/filecoin-project/go-state-types v0.0.0-20201102161440-c8033295a1fc + github.com/filecoin-project/go-state-types v0.0.0-20201203022337-7cab7f0d4bfb github.com/filecoin-project/go-statemachine v0.0.0-20200925024713-05bd7c71fbfe github.com/filecoin-project/go-statestore v0.1.0 github.com/filecoin-project/go-storedcounter v0.0.0-20200421200003-1c99c62e8a5b github.com/filecoin-project/specs-actors v0.9.13 - github.com/filecoin-project/specs-actors/v2 v2.3.3 + github.com/filecoin-project/specs-actors/v2 v2.3.4 + github.com/filecoin-project/specs-actors/v3 v3.0.0-20210115014158-be9804e44879 github.com/filecoin-project/specs-storage v0.1.1-0.20201105051918-5188d9774506 github.com/filecoin-project/test-vectors/schema v0.0.5 github.com/gbrlsnchs/jwt/v3 v3.0.0-beta.1 diff --git a/go.sum b/go.sum index 7f60cef4a..f53d98300 100644 --- a/go.sum +++ b/go.sum @@ -246,6 +246,8 @@ github.com/filecoin-project/go-amt-ipld/v2 v2.1.0 h1:t6qDiuGYYngDqaLc2ZUvdtAg4UN github.com/filecoin-project/go-amt-ipld/v2 v2.1.0/go.mod h1:nfFPoGyX0CU9SkXX8EoCcSuHN1XcbN0c6KBh7yvP5fs= github.com/filecoin-project/go-amt-ipld/v2 v2.1.1-0.20201006184820-924ee87a1349 h1:pIuR0dnMD0i+as8wNnjjHyQrnhP5O5bmba/lmgQeRgU= github.com/filecoin-project/go-amt-ipld/v2 v2.1.1-0.20201006184820-924ee87a1349/go.mod h1:vgmwKBkx+ca5OIeEvstiQgzAZnb7R6QaqE1oEDSqa6g= +github.com/filecoin-project/go-amt-ipld/v3 v3.0.0-20201124192204-2b387ce1bab7 h1:HHKfkAfweGbpnJV60OuG6M0ZAXKrELklLvyjcKI/nKI= +github.com/filecoin-project/go-amt-ipld/v3 v3.0.0-20201124192204-2b387ce1bab7/go.mod h1:Qa95YNAbtoVCTSVtX38aAC1ptBnJfPma1R/zZsKmx4o= github.com/filecoin-project/go-bitfield v0.2.0 h1:gCtLcjskIPtdg4NfN7gQZSQF9yrBQ7mkT0qCJxzGI2Q= github.com/filecoin-project/go-bitfield v0.2.0/go.mod h1:CNl9WG8hgR5mttCnUErjcQjGvuiZjRqK9rHVBsQF4oM= github.com/filecoin-project/go-bitfield v0.2.3-0.20201110211213-fe2c1862e816 h1:RMdzMqe3mu2Z/3N3b9UEfkbGZxukstmZgNC024ybWhA= @@ -273,6 +275,8 @@ github.com/filecoin-project/go-hamt-ipld v0.1.5 h1:uoXrKbCQZ49OHpsTCkrThPNelC4W3 github.com/filecoin-project/go-hamt-ipld v0.1.5/go.mod h1:6Is+ONR5Cd5R6XZoCse1CWaXZc0Hdb/JeX+EQCQzX24= github.com/filecoin-project/go-hamt-ipld/v2 v2.0.0 h1:b3UDemBYN2HNfk3KOXNuxgTTxlWi3xVvbQP0IT38fvM= github.com/filecoin-project/go-hamt-ipld/v2 v2.0.0/go.mod h1:7aWZdaQ1b16BVoQUYR+eEvrDCGJoPLxFpDynFjYfBjI= +github.com/filecoin-project/go-hamt-ipld/v3 v3.0.0-20201203140949-5cdbb5191437 h1:nu2XYXvzy6BNASKVpfCkmUFr6YDf43LMjkMMab+3Z1E= +github.com/filecoin-project/go-hamt-ipld/v3 v3.0.0-20201203140949-5cdbb5191437/go.mod h1:HBuSIxbIKqWjV0/bcJ/e14iIMr1FckG6cyzAsdfttyU= github.com/filecoin-project/go-jsonrpc v0.1.2 h1:MTebUawBHLxxY9gDi1WXuGc89TWIDmsgoDqeZSk9KRw= github.com/filecoin-project/go-jsonrpc v0.1.2/go.mod h1:XBBpuKIMaXIIzeqzO1iucq4GvbF8CxmXRFoezRh+Cx4= github.com/filecoin-project/go-multistore v0.0.3 h1:vaRBY4YiA2UZFPK57RNuewypB8u0DzzQwqsL0XarpnI= @@ -286,6 +290,8 @@ github.com/filecoin-project/go-state-types v0.0.0-20200904021452-1883f36ca2f4/go github.com/filecoin-project/go-state-types v0.0.0-20200928172055-2df22083d8ab/go.mod h1:ezYnPf0bNkTsDibL/psSz5dy4B5awOJ/E7P2Saeep8g= github.com/filecoin-project/go-state-types v0.0.0-20201102161440-c8033295a1fc h1:+hbMY4Pcx2oizrfH08VWXwrj5mU8aJT6g0UNxGHFCGU= github.com/filecoin-project/go-state-types v0.0.0-20201102161440-c8033295a1fc/go.mod h1:ezYnPf0bNkTsDibL/psSz5dy4B5awOJ/E7P2Saeep8g= +github.com/filecoin-project/go-state-types v0.0.0-20201203022337-7cab7f0d4bfb h1:f7Y9QeUfT+hX+OOjtZ3j1e2KlGWg7ozI7W444Qa+ZJ0= +github.com/filecoin-project/go-state-types v0.0.0-20201203022337-7cab7f0d4bfb/go.mod h1:ezYnPf0bNkTsDibL/psSz5dy4B5awOJ/E7P2Saeep8g= github.com/filecoin-project/go-statemachine v0.0.0-20200925024713-05bd7c71fbfe h1:dF8u+LEWeIcTcfUcCf3WFVlc81Fr2JKg8zPzIbBDKDw= github.com/filecoin-project/go-statemachine v0.0.0-20200925024713-05bd7c71fbfe/go.mod h1:FGwQgZAt2Gh5mjlwJUlVB62JeYdo+if0xWxSEfBD9ig= github.com/filecoin-project/go-statestore v0.1.0 h1:t56reH59843TwXHkMcwyuayStBIiWBRilQjQ+5IiwdQ= @@ -299,8 +305,10 @@ github.com/filecoin-project/specs-actors v0.9.13/go.mod h1:TS1AW/7LbG+615j4NsjMK github.com/filecoin-project/specs-actors/v2 v2.0.1/go.mod h1:v2NZVYinNIKA9acEMBm5wWXxqv5+frFEbekBFemYghY= github.com/filecoin-project/specs-actors/v2 v2.3.2 h1:2Vcf4CGa29kRh4JJ02m+FbvD/p3YNnLGsaHfw7Uj49g= github.com/filecoin-project/specs-actors/v2 v2.3.2/go.mod h1:UuJQLoTx/HPvvWeqlIFmC/ywlOLHNe8SNQ3OunFbu2Y= -github.com/filecoin-project/specs-actors/v2 v2.3.3 h1:5Pd6pjU7VjUye+Hz4gYBCPAFdBxtEbHsgGYvWmfc83w= -github.com/filecoin-project/specs-actors/v2 v2.3.3/go.mod h1:UuJQLoTx/HPvvWeqlIFmC/ywlOLHNe8SNQ3OunFbu2Y= +github.com/filecoin-project/specs-actors/v2 v2.3.4 h1:NZK2oMCcA71wNsUzDBmLQyRMzcCnX9tDGvwZ53G67j8= +github.com/filecoin-project/specs-actors/v2 v2.3.4/go.mod h1:UuJQLoTx/HPvvWeqlIFmC/ywlOLHNe8SNQ3OunFbu2Y= +github.com/filecoin-project/specs-actors/v3 v3.0.0-20210115014158-be9804e44879 h1:rX+rISGIh3/VQf/rXPAQ0waJ2JDXCO/o68pmIP+zQHk= +github.com/filecoin-project/specs-actors/v3 v3.0.0-20210115014158-be9804e44879/go.mod h1:kJ/Jk5TYkSC7eJR4RPl2VYgYJOsLPeERAmGkeFMXiLM= github.com/filecoin-project/specs-storage v0.1.1-0.20201105051918-5188d9774506 h1:Ur/l2+6qN+lQiqjozWWc5p9UDaAMDZKTlDS98oRnlIw= github.com/filecoin-project/specs-storage v0.1.1-0.20201105051918-5188d9774506/go.mod h1:nJRRM7Aa9XVvygr3W9k6xGF46RWzr2zxF/iGoAIfA/g= github.com/filecoin-project/test-vectors/schema v0.0.5 h1:w3zHQhzM4pYxJDl21avXjOKBLF8egrvwUwjpT8TquDg= From 3961e3daf816442d3259900eeeb0538cc8a74aff Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Fri, 15 Jan 2021 23:14:20 -0500 Subject: [PATCH 02/58] Add v3 actors support for account --- chain/actors/builtin/account/account.go | 3 +++ chain/actors/builtin/account/v3.go | 30 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 chain/actors/builtin/account/v3.go diff --git a/chain/actors/builtin/account/account.go b/chain/actors/builtin/account/account.go index 38ed2654b..c77d5b540 100644 --- a/chain/actors/builtin/account/account.go +++ b/chain/actors/builtin/account/account.go @@ -13,6 +13,7 @@ import ( builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" + builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" ) func init() { @@ -32,6 +33,8 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return load0(store, act.Head) case builtin2.AccountActorCodeID: return load2(store, act.Head) + case builtin3.AccountActorCodeID: + return load3(store, act.Head) } return nil, xerrors.Errorf("unknown actor code %s", act.Code) } diff --git a/chain/actors/builtin/account/v3.go b/chain/actors/builtin/account/v3.go new file mode 100644 index 000000000..16b489a3e --- /dev/null +++ b/chain/actors/builtin/account/v3.go @@ -0,0 +1,30 @@ +package account + +import ( + "github.com/filecoin-project/go-address" + "github.com/ipfs/go-cid" + + "github.com/filecoin-project/lotus/chain/actors/adt" + + account3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/account" +) + +var _ State = (*state3)(nil) + +func load3(store adt.Store, root cid.Cid) (State, error) { + out := state3{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +type state3 struct { + account3.State + store adt.Store +} + +func (s *state3) PubkeyAddress() (address.Address, error) { + return s.Address, nil +} From 378f169f14410d77530d2cd2128ed07744d9818f Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Fri, 15 Jan 2021 23:21:33 -0500 Subject: [PATCH 03/58] Add v3 actors support for init --- chain/actors/builtin/init/init.go | 3 ++ chain/actors/builtin/init/v3.go | 86 +++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 chain/actors/builtin/init/v3.go diff --git a/chain/actors/builtin/init/init.go b/chain/actors/builtin/init/init.go index 466af6a6c..7635117cd 100644 --- a/chain/actors/builtin/init/init.go +++ b/chain/actors/builtin/init/init.go @@ -15,6 +15,7 @@ import ( builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" + builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" ) func init() { @@ -37,6 +38,8 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return load0(store, act.Head) case builtin2.InitActorCodeID: return load2(store, act.Head) + case builtin3.InitActorCodeID: + return load3(store, act.Head) } return nil, xerrors.Errorf("unknown actor code %s", act.Code) } diff --git a/chain/actors/builtin/init/v3.go b/chain/actors/builtin/init/v3.go new file mode 100644 index 000000000..e586b3b11 --- /dev/null +++ b/chain/actors/builtin/init/v3.go @@ -0,0 +1,86 @@ +package init + +import ( + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" + "github.com/ipfs/go-cid" + cbg "github.com/whyrusleeping/cbor-gen" + "golang.org/x/xerrors" + + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/node/modules/dtypes" + + init3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/init" + adt3 "github.com/filecoin-project/specs-actors/v3/actors/util/adt" +) + +var _ State = (*state3)(nil) + +func load3(store adt.Store, root cid.Cid) (State, error) { + out := state3{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +type state3 struct { + init3.State + store adt.Store +} + +func (s *state3) ResolveAddress(address address.Address) (address.Address, bool, error) { + return s.State.ResolveAddress(s.store, address) +} + +func (s *state3) MapAddressToNewID(address address.Address) (address.Address, error) { + return s.State.MapAddressToNewID(s.store, address) +} + +func (s *state3) ForEachActor(cb func(id abi.ActorID, address address.Address) error) error { + addrs, err := adt3.AsMap(s.store, s.State.AddressMap, builtin3.DefaultHamtBitwidth) + if err != nil { + return err + } + var actorID cbg.CborInt + return addrs.ForEach(&actorID, func(key string) error { + addr, err := address.NewFromBytes([]byte(key)) + if err != nil { + return err + } + return cb(abi.ActorID(actorID), addr) + }) +} + +func (s *state3) NetworkName() (dtypes.NetworkName, error) { + return dtypes.NetworkName(s.State.NetworkName), nil +} + +func (s *state3) SetNetworkName(name string) error { + s.State.NetworkName = name + return nil +} + +func (s *state3) Remove(addrs ...address.Address) (err error) { + m, err := adt3.AsMap(s.store, s.State.AddressMap, builtin3.DefaultHamtBitwidth) + if err != nil { + return err + } + for _, addr := range addrs { + if err = m.Delete(abi.AddrKey(addr)); err != nil { + return xerrors.Errorf("failed to delete entry for address: %s; err: %w", addr, err) + } + } + amr, err := m.Root() + if err != nil { + return xerrors.Errorf("failed to get address map root: %w", err) + } + s.State.AddressMap = amr + return nil +} + +func (s *state3) addressMap() (adt.Map, error) { + return adt3.AsMap(s.store, s.AddressMap, builtin3.DefaultHamtBitwidth) +} From b4f479affd6297c2c6ccd48fe47e946d90ad27e6 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Fri, 15 Jan 2021 23:58:18 -0500 Subject: [PATCH 04/58] Add v3 actors support for market --- chain/actors/builtin/market/market.go | 3 + chain/actors/builtin/market/v3.go | 205 ++++++++++++++++++++++++++ 2 files changed, 208 insertions(+) create mode 100644 chain/actors/builtin/market/v3.go diff --git a/chain/actors/builtin/market/market.go b/chain/actors/builtin/market/market.go index 8bb31f2b4..49ad06436 100644 --- a/chain/actors/builtin/market/market.go +++ b/chain/actors/builtin/market/market.go @@ -12,6 +12,7 @@ import ( builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" market0 "github.com/filecoin-project/specs-actors/actors/builtin/market" builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" + builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/actors/builtin" @@ -38,6 +39,8 @@ func Load(store adt.Store, act *types.Actor) (st State, err error) { return load0(store, act.Head) case builtin2.StorageMarketActorCodeID: return load2(store, act.Head) + case builtin3.StorageMarketActorCodeID: + return load3(store, act.Head) } return nil, xerrors.Errorf("unknown actor code %s", act.Code) } diff --git a/chain/actors/builtin/market/v3.go b/chain/actors/builtin/market/v3.go new file mode 100644 index 000000000..3309d37a7 --- /dev/null +++ b/chain/actors/builtin/market/v3.go @@ -0,0 +1,205 @@ +package market + +import ( + "bytes" + + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + "github.com/ipfs/go-cid" + cbg "github.com/whyrusleeping/cbor-gen" + + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/types" + + market3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/market" + adt3 "github.com/filecoin-project/specs-actors/v3/actors/util/adt" +) + +var _ State = (*state3)(nil) + +func load3(store adt.Store, root cid.Cid) (State, error) { + out := state3{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +type state3 struct { + market3.State + store adt.Store +} + +func (s *state3) TotalLocked() (abi.TokenAmount, error) { + fml := types.BigAdd(s.TotalClientLockedCollateral, s.TotalProviderLockedCollateral) + fml = types.BigAdd(fml, s.TotalClientStorageFee) + return fml, nil +} + +func (s *state3) BalancesChanged(otherState State) (bool, error) { + otherState2, ok := otherState.(*state3) + if !ok { + // there's no way to compare different versions of the state, so let's + // just say that means the state of balances has changed + return true, nil + } + return !s.State.EscrowTable.Equals(otherState2.State.EscrowTable) || !s.State.LockedTable.Equals(otherState2.State.LockedTable), nil +} + +func (s *state3) StatesChanged(otherState State) (bool, error) { + otherState2, ok := otherState.(*state3) + if !ok { + // there's no way to compare different versions of the state, so let's + // just say that means the state of balances has changed + return true, nil + } + return !s.State.States.Equals(otherState2.State.States), nil +} + +func (s *state3) States() (DealStates, error) { + stateArray, err := adt3.AsArray(s.store, s.State.States, market3.StatesAmtBitwidth) + if err != nil { + return nil, err + } + return &dealStates3{stateArray}, nil +} + +func (s *state3) ProposalsChanged(otherState State) (bool, error) { + otherState2, ok := otherState.(*state3) + if !ok { + // there's no way to compare different versions of the state, so let's + // just say that means the state of balances has changed + return true, nil + } + return !s.State.Proposals.Equals(otherState2.State.Proposals), nil +} + +func (s *state3) Proposals() (DealProposals, error) { + proposalArray, err := adt3.AsArray(s.store, s.State.Proposals, market3.ProposalsAmtBitwidth) + if err != nil { + return nil, err + } + return &dealProposals3{proposalArray}, nil +} + +func (s *state3) EscrowTable() (BalanceTable, error) { + bt, err := adt3.AsBalanceTable(s.store, s.State.EscrowTable) + if err != nil { + return nil, err + } + return &balanceTable3{bt}, nil +} + +func (s *state3) LockedTable() (BalanceTable, error) { + bt, err := adt3.AsBalanceTable(s.store, s.State.LockedTable) + if err != nil { + return nil, err + } + return &balanceTable3{bt}, nil +} + +func (s *state3) VerifyDealsForActivation( + minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch, +) (weight, verifiedWeight abi.DealWeight, err error) { + w, vw, _, err := market3.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) + return w, vw, err +} + +type balanceTable3 struct { + *adt3.BalanceTable +} + +func (bt *balanceTable3) ForEach(cb func(address.Address, abi.TokenAmount) error) error { + asMap := (*adt3.Map)(bt.BalanceTable) + var ta abi.TokenAmount + return asMap.ForEach(&ta, func(key string) error { + a, err := address.NewFromBytes([]byte(key)) + if err != nil { + return err + } + return cb(a, ta) + }) +} + +type dealStates3 struct { + adt.Array +} + +func (s *dealStates3) Get(dealID abi.DealID) (*DealState, bool, error) { + var deal2 market3.DealState + found, err := s.Array.Get(uint64(dealID), &deal2) + if err != nil { + return nil, false, err + } + if !found { + return nil, false, nil + } + deal := fromV3DealState(deal2) + return &deal, true, nil +} + +func (s *dealStates3) ForEach(cb func(dealID abi.DealID, ds DealState) error) error { + var ds1 market3.DealState + return s.Array.ForEach(&ds1, func(idx int64) error { + return cb(abi.DealID(idx), fromV3DealState(ds1)) + }) +} + +func (s *dealStates3) decode(val *cbg.Deferred) (*DealState, error) { + var ds1 market3.DealState + if err := ds1.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { + return nil, err + } + ds := fromV3DealState(ds1) + return &ds, nil +} + +func (s *dealStates3) array() adt.Array { + return s.Array +} + +func fromV3DealState(v1 market3.DealState) DealState { + return (DealState)(v1) +} + +type dealProposals3 struct { + adt.Array +} + +func (s *dealProposals3) Get(dealID abi.DealID) (*DealProposal, bool, error) { + var proposal2 market3.DealProposal + found, err := s.Array.Get(uint64(dealID), &proposal2) + if err != nil { + return nil, false, err + } + if !found { + return nil, false, nil + } + proposal := fromV3DealProposal(proposal2) + return &proposal, true, nil +} + +func (s *dealProposals3) ForEach(cb func(dealID abi.DealID, dp DealProposal) error) error { + var dp1 market3.DealProposal + return s.Array.ForEach(&dp1, func(idx int64) error { + return cb(abi.DealID(idx), fromV3DealProposal(dp1)) + }) +} + +func (s *dealProposals3) decode(val *cbg.Deferred) (*DealProposal, error) { + var dp1 market3.DealProposal + if err := dp1.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { + return nil, err + } + dp := fromV3DealProposal(dp1) + return &dp, nil +} + +func (s *dealProposals3) array() adt.Array { + return s.Array +} + +func fromV3DealProposal(v1 market3.DealProposal) DealProposal { + return (DealProposal)(v1) +} From 82635f2515fb4612d189426a5750256ea5fd593c Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Sat, 16 Jan 2021 00:53:27 -0500 Subject: [PATCH 05/58] Rename Deadline.PoStSubmissions to PartitionsPoSted --- chain/actors/builtin/miner/miner.go | 2 +- chain/actors/builtin/miner/v0.go | 2 +- chain/actors/builtin/miner/v2.go | 2 +- node/impl/full/state.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index 066dc9bfd..248412b90 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -96,7 +96,7 @@ type State interface { type Deadline interface { LoadPartition(idx uint64) (Partition, error) ForEachPartition(cb func(idx uint64, part Partition) error) error - PostSubmissions() (bitfield.BitField, error) + PartitionsPoSted() (bitfield.BitField, error) PartitionsChanged(Deadline) (bool, error) } diff --git a/chain/actors/builtin/miner/v0.go b/chain/actors/builtin/miner/v0.go index 69160e4e0..7967a5fc3 100644 --- a/chain/actors/builtin/miner/v0.go +++ b/chain/actors/builtin/miner/v0.go @@ -382,7 +382,7 @@ func (d *deadline0) PartitionsChanged(other Deadline) (bool, error) { return !d.Deadline.Partitions.Equals(other0.Deadline.Partitions), nil } -func (d *deadline0) PostSubmissions() (bitfield.BitField, error) { +func (d *deadline0) PartitionsPoSted() (bitfield.BitField, error) { return d.Deadline.PostSubmissions, nil } diff --git a/chain/actors/builtin/miner/v2.go b/chain/actors/builtin/miner/v2.go index 2c67484ea..5130a218e 100644 --- a/chain/actors/builtin/miner/v2.go +++ b/chain/actors/builtin/miner/v2.go @@ -381,7 +381,7 @@ func (d *deadline2) PartitionsChanged(other Deadline) (bool, error) { return !d.Deadline.Partitions.Equals(other2.Deadline.Partitions), nil } -func (d *deadline2) PostSubmissions() (bitfield.BitField, error) { +func (d *deadline2) PartitionsPoSted() (bitfield.BitField, error) { return d.Deadline.PostSubmissions, nil } diff --git a/node/impl/full/state.go b/node/impl/full/state.go index b92813f7a..784bb890d 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -170,7 +170,7 @@ func (a *StateAPI) StateMinerDeadlines(ctx context.Context, m address.Address, t out := make([]api.Deadline, deadlines) if err := mas.ForEachDeadline(func(i uint64, dl miner.Deadline) error { - ps, err := dl.PostSubmissions() + ps, err := dl.PartitionsPoSted() if err != nil { return err } From ab90a3b2bc3d09ab3d615cb7b07cb876d823979f Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Sat, 16 Jan 2021 01:42:56 -0500 Subject: [PATCH 06/58] Actors update: MinerInfo.SealProofType has been removed --- chain/actors/builtin/miner/miner.go | 20 +++++++++++++++++++- chain/actors/builtin/miner/v0.go | 7 ++++++- chain/actors/builtin/miner/v2.go | 7 ++++++- chain/stmgr/utils.go | 7 +------ cmd/lotus-storage-miner/proving.go | 7 +------ extern/storage-sealing/sealing.go | 2 +- markets/storageadapter/provider.go | 4 +++- node/impl/client/client.go | 9 ++++++++- node/impl/full/state.go | 5 ----- node/modules/storageminer.go | 4 +++- storage/miner.go | 7 +------ storage/wdpost_sched.go | 7 +------ 12 files changed, 50 insertions(+), 36 deletions(-) diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index 248412b90..cb147bf45 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -143,6 +143,24 @@ type DeclareFaultsRecoveredParams = miner0.DeclareFaultsRecoveredParams type SubmitWindowedPoStParams = miner0.SubmitWindowedPoStParams type ProveCommitSectorParams = miner0.ProveCommitSectorParams +// TODO: This may need to be epoch-sensitive +func PreferredSealProofTypeFromWindowPoStType(proof abi.RegisteredPoStProof) (abi.RegisteredSealProof, error) { + switch proof { + case abi.RegisteredPoStProof_StackedDrgWindow2KiBV1: + return abi.RegisteredSealProof_StackedDrg2KiBV1_1, nil + case abi.RegisteredPoStProof_StackedDrgWindow8MiBV1: + return abi.RegisteredSealProof_StackedDrg8MiBV1_1, nil + case abi.RegisteredPoStProof_StackedDrgWindow512MiBV1: + return abi.RegisteredSealProof_StackedDrg512MiBV1_1, nil + case abi.RegisteredPoStProof_StackedDrgWindow32GiBV1: + return abi.RegisteredSealProof_StackedDrg32GiBV1_1, nil + case abi.RegisteredPoStProof_StackedDrgWindow64GiBV1: + return abi.RegisteredSealProof_StackedDrg64GiBV1_1, nil + default: + return -1, xerrors.Errorf("unrecognized window post type: %d", proof) + } +} + type MinerInfo struct { Owner address.Address // Must be an ID-address. Worker address.Address // Must be an ID-address. @@ -151,7 +169,7 @@ type MinerInfo struct { WorkerChangeEpoch abi.ChainEpoch PeerId *peer.ID Multiaddrs []abi.Multiaddrs - SealProofType abi.RegisteredSealProof + WindowPoStProofType abi.RegisteredPoStProof SectorSize abi.SectorSize WindowPoStPartitionSectors uint64 ConsensusFaultElapsed abi.ChainEpoch diff --git a/chain/actors/builtin/miner/v0.go b/chain/actors/builtin/miner/v0.go index 7967a5fc3..2795d6d70 100644 --- a/chain/actors/builtin/miner/v0.go +++ b/chain/actors/builtin/miner/v0.go @@ -297,6 +297,11 @@ func (s *state0) Info() (MinerInfo, error) { pid = &peerID } + wpp, err := info.SealProofType.RegisteredWindowPoStProof() + if err != nil { + return MinerInfo{}, err + } + mi := MinerInfo{ Owner: info.Owner, Worker: info.Worker, @@ -307,7 +312,7 @@ func (s *state0) Info() (MinerInfo, error) { PeerId: pid, Multiaddrs: info.Multiaddrs, - SealProofType: info.SealProofType, + WindowPoStProofType: wpp, SectorSize: info.SectorSize, WindowPoStPartitionSectors: info.WindowPoStPartitionSectors, ConsensusFaultElapsed: -1, diff --git a/chain/actors/builtin/miner/v2.go b/chain/actors/builtin/miner/v2.go index 5130a218e..854aa6ab7 100644 --- a/chain/actors/builtin/miner/v2.go +++ b/chain/actors/builtin/miner/v2.go @@ -296,6 +296,11 @@ func (s *state2) Info() (MinerInfo, error) { pid = &peerID } + wpp, err := info.SealProofType.RegisteredWindowPoStProof() + if err != nil { + return MinerInfo{}, err + } + mi := MinerInfo{ Owner: info.Owner, Worker: info.Worker, @@ -306,7 +311,7 @@ func (s *state2) Info() (MinerInfo, error) { PeerId: pid, Multiaddrs: info.Multiaddrs, - SealProofType: info.SealProofType, + WindowPoStProofType: wpp, SectorSize: info.SectorSize, WindowPoStPartitionSectors: info.WindowPoStPartitionSectors, ConsensusFaultElapsed: info.ConsensusFaultElapsed, diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index 1e29e72d8..ce0384842 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -207,17 +207,12 @@ func GetSectorsForWinningPoSt(ctx context.Context, nv network.Version, pv ffiwra return nil, xerrors.Errorf("getting miner info: %w", err) } - wpt, err := info.SealProofType.RegisteredWinningPoStProof() - if err != nil { - return nil, xerrors.Errorf("getting window proof type: %w", err) - } - mid, err := address.IDFromAddress(maddr) if err != nil { return nil, xerrors.Errorf("getting miner ID: %w", err) } - ids, err := pv.GenerateWinningPoStSectorChallenge(ctx, wpt, abi.ActorID(mid), rand, numProvSect) + ids, err := pv.GenerateWinningPoStSectorChallenge(ctx, info.WindowPoStProofType, abi.ActorID(mid), rand, numProvSect) if err != nil { return nil, xerrors.Errorf("generating winning post challenges: %w", err) } diff --git a/cmd/lotus-storage-miner/proving.go b/cmd/lotus-storage-miner/proving.go index 6f379e99c..3d60f4b76 100644 --- a/cmd/lotus-storage-miner/proving.go +++ b/cmd/lotus-storage-miner/proving.go @@ -430,11 +430,6 @@ var provingCheckProvableCmd = &cli.Command{ return err } - pf, err := info.SealProofType.RegisteredWindowPoStProof() - if err != nil { - return err - } - partitions, err := api.StateMinerPartitions(ctx, addr, dlIdx, types.EmptyTSK) if err != nil { return err @@ -463,7 +458,7 @@ var provingCheckProvableCmd = &cli.Command{ }) } - bad, err := sapi.CheckProvable(ctx, pf, tocheck, cctx.Bool("slow")) + bad, err := sapi.CheckProvable(ctx, info.WindowPoStProofType, tocheck, cctx.Bool("slow")) if err != nil { return err } diff --git a/extern/storage-sealing/sealing.go b/extern/storage-sealing/sealing.go index 96d63efdc..2219d9d2c 100644 --- a/extern/storage-sealing/sealing.go +++ b/extern/storage-sealing/sealing.go @@ -475,7 +475,7 @@ func (m *Sealing) currentSealProof(ctx context.Context) (abi.RegisteredSealProof return 0, err } - return mi.SealProofType, nil + return miner.PreferredSealProofTypeFromWindowPoStType(mi.WindowPoStProofType) } func (m *Sealing) minerSector(spt abi.RegisteredSealProof, num abi.SectorNumber) storage.SectorRef { diff --git a/markets/storageadapter/provider.go b/markets/storageadapter/provider.go index 085888ee3..6a06c46e3 100644 --- a/markets/storageadapter/provider.go +++ b/markets/storageadapter/provider.go @@ -7,6 +7,8 @@ import ( "io" "time" + miner2 "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + "github.com/ipfs/go-cid" logging "github.com/ipfs/go-log/v2" "golang.org/x/xerrors" @@ -179,7 +181,7 @@ func (n *ProviderNodeAdapter) GetProofType(ctx context.Context, miner address.Ad if err != nil { return 0, err } - return mi.SealProofType, nil + return miner2.PreferredSealProofTypeFromWindowPoStType(mi.WindowPoStProofType) } func (n *ProviderNodeAdapter) SignBytes(ctx context.Context, signer address.Address, b []byte) (*crypto.Signature, error) { diff --git a/node/impl/client/client.go b/node/impl/client/client.go index e90a31a80..3868e69ea 100644 --- a/node/impl/client/client.go +++ b/node/impl/client/client.go @@ -7,6 +7,8 @@ import ( "io" "os" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + "golang.org/x/xerrors" "github.com/filecoin-project/go-padreader" @@ -157,6 +159,11 @@ func (a *API) ClientStartDeal(ctx context.Context, params *api.StartDealParams) dealStart = ts.Height() + abi.ChainEpoch(dealStartBufferHours*blocksPerHour) // TODO: Get this from storage ask } + st, err := miner.PreferredSealProofTypeFromWindowPoStType(mi.WindowPoStProofType) + if err != nil { + return nil, xerrors.Errorf("failed to get seal proof type: %w", err) + } + result, err := a.SMDealClient.ProposeStorageDeal(ctx, storagemarket.ProposeStorageDealParams{ Addr: params.Wallet, Info: &providerInfo, @@ -165,7 +172,7 @@ func (a *API) ClientStartDeal(ctx context.Context, params *api.StartDealParams) EndEpoch: calcDealExpiration(params.MinBlocksDuration, md, dealStart), Price: params.EpochPrice, Collateral: params.ProviderCollateral, - Rt: mi.SealProofType, + Rt: st, FastRetrieval: params.FastRetrieval, VerifiedDeal: params.VerifiedDeal, StoreID: storeID, diff --git a/node/impl/full/state.go b/node/impl/full/state.go index 784bb890d..cecf8ef55 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -140,15 +140,10 @@ func (m *StateModule) StateMinerInfo(ctx context.Context, actor address.Address, return miner.MinerInfo{}, xerrors.Errorf("failed to load miner actor state: %w", err) } - // TODO: You know, this is terrible. - // I mean, we _really_ shouldn't do this. Maybe we should convert somewhere else? info, err := mas.Info() if err != nil { return miner.MinerInfo{}, err } - if m.StateManager.GetNtwkVersion(ctx, ts.Height()) >= network.Version7 && info.SealProofType < abi.RegisteredSealProof_StackedDrg2KiBV1_1 { - info.SealProofType += abi.RegisteredSealProof_StackedDrg2KiBV1_1 - } return info, nil } diff --git a/node/modules/storageminer.go b/node/modules/storageminer.go index 30f84aeaf..165e98e01 100644 --- a/node/modules/storageminer.go +++ b/node/modules/storageminer.go @@ -10,6 +10,8 @@ import ( "path/filepath" "time" + miner2 "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + "go.uber.org/fx" "go.uber.org/multierr" "golang.org/x/xerrors" @@ -128,7 +130,7 @@ func SealProofType(maddr dtypes.MinerAddress, fnapi lapi.FullNode) (abi.Register return 0, err } - return mi.SealProofType, nil + return miner2.PreferredSealProofTypeFromWindowPoStType(mi.WindowPoStProofType) } type sidsc struct { diff --git a/storage/miner.go b/storage/miner.go index 752d7ff42..425664991 100644 --- a/storage/miner.go +++ b/storage/miner.go @@ -225,18 +225,13 @@ func NewWinningPoStProver(api api.FullNode, prover storage.Prover, verifier ffiw return nil, xerrors.Errorf("getting sector size: %w", err) } - wpt, err := mi.SealProofType.RegisteredWinningPoStProof() - if err != nil { - return nil, err - } - if build.InsecurePoStValidation { log.Warn("*****************************************************************************") log.Warn(" Generating fake PoSt proof! You should only see this while running tests! ") log.Warn("*****************************************************************************") } - return &StorageWpp{prover, verifier, abi.ActorID(miner), wpt}, nil + return &StorageWpp{prover, verifier, abi.ActorID(miner), mi.WindowPoStProofType}, nil } var _ gen.WinningPoStProver = (*StorageWpp)(nil) diff --git a/storage/wdpost_sched.go b/storage/wdpost_sched.go index f81a60a1e..3d6073a63 100644 --- a/storage/wdpost_sched.go +++ b/storage/wdpost_sched.go @@ -47,18 +47,13 @@ func NewWindowedPoStScheduler(api storageMinerApi, fc config.MinerFeeConfig, as return nil, xerrors.Errorf("getting sector size: %w", err) } - rt, err := mi.SealProofType.RegisteredWindowPoStProof() - if err != nil { - return nil, err - } - return &WindowPoStScheduler{ api: api, feeCfg: fc, addrSel: as, prover: sb, faultTracker: ft, - proofType: rt, + proofType: mi.WindowPoStProofType, partitionSectors: mi.WindowPoStPartitionSectors, actor: actor, From 0bb3aed53cf8baf8a5a3376995de69d977cfcd2f Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Sat, 16 Jan 2021 01:44:36 -0500 Subject: [PATCH 07/58] Add v3 actors support for miner --- chain/actors/builtin/miner/miner.go | 6 +- chain/actors/builtin/miner/v3.go | 425 ++++++++++++++++++++++++++++ 2 files changed, 430 insertions(+), 1 deletion(-) create mode 100644 chain/actors/builtin/miner/v3.go diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index cb147bf45..e520e07d5 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -21,6 +21,7 @@ import ( miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" miner2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/miner" + builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" ) func init() { @@ -30,11 +31,14 @@ func init() { builtin.RegisterActorState(builtin2.StorageMinerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { return load2(store, root) }) + builtin.RegisterActorState(builtin3.StorageMinerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { + return load3(store, root) + }) } var Methods = builtin2.MethodsMiner -// Unchanged between v0 and v2 actors +// Unchanged between v0, v2, and v3 actors var WPoStProvingPeriod = miner0.WPoStProvingPeriod var WPoStPeriodDeadlines = miner0.WPoStPeriodDeadlines var WPoStChallengeWindow = miner0.WPoStChallengeWindow diff --git a/chain/actors/builtin/miner/v3.go b/chain/actors/builtin/miner/v3.go new file mode 100644 index 000000000..2d2ecacf4 --- /dev/null +++ b/chain/actors/builtin/miner/v3.go @@ -0,0 +1,425 @@ +package miner + +import ( + "bytes" + "errors" + + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-bitfield" + "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/go-state-types/dline" + "github.com/ipfs/go-cid" + "github.com/libp2p/go-libp2p-core/peer" + cbg "github.com/whyrusleeping/cbor-gen" + "golang.org/x/xerrors" + + "github.com/filecoin-project/lotus/chain/actors/adt" + + builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" + miner3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/miner" + adt3 "github.com/filecoin-project/specs-actors/v3/actors/util/adt" +) + +var _ State = (*state3)(nil) + +func load3(store adt.Store, root cid.Cid) (State, error) { + out := state3{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +type state3 struct { + miner3.State + store adt.Store +} + +type deadline3 struct { + miner3.Deadline + store adt.Store +} + +type partition3 struct { + miner3.Partition + store adt.Store +} + +func (s *state3) AvailableBalance(bal abi.TokenAmount) (available abi.TokenAmount, err error) { + defer func() { + if r := recover(); r != nil { + err = xerrors.Errorf("failed to get available balance: %w", r) + available = abi.NewTokenAmount(0) + } + }() + // this panics if the miner doesnt have enough funds to cover their locked pledge + available, err = s.GetAvailableBalance(bal) + return available, err +} + +func (s *state3) VestedFunds(epoch abi.ChainEpoch) (abi.TokenAmount, error) { + return s.CheckVestedFunds(s.store, epoch) +} + +func (s *state3) LockedFunds() (LockedFunds, error) { + return LockedFunds{ + VestingFunds: s.State.LockedFunds, + InitialPledgeRequirement: s.State.InitialPledge, + PreCommitDeposits: s.State.PreCommitDeposits, + }, nil +} + +func (s *state3) FeeDebt() (abi.TokenAmount, error) { + return s.State.FeeDebt, nil +} + +func (s *state3) InitialPledge() (abi.TokenAmount, error) { + return s.State.InitialPledge, nil +} + +func (s *state3) PreCommitDeposits() (abi.TokenAmount, error) { + return s.State.PreCommitDeposits, nil +} + +func (s *state3) GetSector(num abi.SectorNumber) (*SectorOnChainInfo, error) { + info, ok, err := s.State.GetSector(s.store, num) + if !ok || err != nil { + return nil, err + } + + ret := fromV3SectorOnChainInfo(*info) + return &ret, nil +} + +func (s *state3) FindSector(num abi.SectorNumber) (*SectorLocation, error) { + dlIdx, partIdx, err := s.State.FindSector(s.store, num) + if err != nil { + return nil, err + } + return &SectorLocation{ + Deadline: dlIdx, + Partition: partIdx, + }, nil +} + +func (s *state3) NumLiveSectors() (uint64, error) { + dls, err := s.State.LoadDeadlines(s.store) + if err != nil { + return 0, err + } + var total uint64 + if err := dls.ForEach(s.store, func(dlIdx uint64, dl *miner3.Deadline) error { + total += dl.LiveSectors + return nil + }); err != nil { + return 0, err + } + return total, nil +} + +// GetSectorExpiration returns the effective expiration of the given sector. +// +// If the sector does not expire early, the Early expiration field is 0. +func (s *state3) GetSectorExpiration(num abi.SectorNumber) (*SectorExpiration, error) { + dls, err := s.State.LoadDeadlines(s.store) + if err != nil { + return nil, err + } + // NOTE: this can be optimized significantly. + // 1. If the sector is non-faulty, it will either expire on-time (can be + // learned from the sector info), or in the next quantized expiration + // epoch (i.e., the first element in the partition's expiration queue. + // 2. If it's faulty, it will expire early within the first 14 entries + // of the expiration queue. + stopErr := errors.New("stop") + out := SectorExpiration{} + err = dls.ForEach(s.store, func(dlIdx uint64, dl *miner3.Deadline) error { + partitions, err := dl.PartitionsArray(s.store) + if err != nil { + return err + } + quant := s.State.QuantSpecForDeadline(dlIdx) + var part miner3.Partition + return partitions.ForEach(&part, func(partIdx int64) error { + if found, err := part.Sectors.IsSet(uint64(num)); err != nil { + return err + } else if !found { + return nil + } + if found, err := part.Terminated.IsSet(uint64(num)); err != nil { + return err + } else if found { + // already terminated + return stopErr + } + + q, err := miner3.LoadExpirationQueue(s.store, part.ExpirationsEpochs, quant, miner3.PartitionExpirationAmtBitwidth) + if err != nil { + return err + } + var exp miner3.ExpirationSet + return q.ForEach(&exp, func(epoch int64) error { + if early, err := exp.EarlySectors.IsSet(uint64(num)); err != nil { + return err + } else if early { + out.Early = abi.ChainEpoch(epoch) + return nil + } + if onTime, err := exp.OnTimeSectors.IsSet(uint64(num)); err != nil { + return err + } else if onTime { + out.OnTime = abi.ChainEpoch(epoch) + return stopErr + } + return nil + }) + }) + }) + if err == stopErr { + err = nil + } + if err != nil { + return nil, err + } + if out.Early == 0 && out.OnTime == 0 { + return nil, xerrors.Errorf("failed to find sector %d", num) + } + return &out, nil +} + +func (s *state3) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitOnChainInfo, error) { + info, ok, err := s.State.GetPrecommittedSector(s.store, num) + if !ok || err != nil { + return nil, err + } + + ret := fromV3SectorPreCommitOnChainInfo(*info) + + return &ret, nil +} + +func (s *state3) LoadSectors(snos *bitfield.BitField) ([]*SectorOnChainInfo, error) { + sectors, err := miner3.LoadSectors(s.store, s.State.Sectors) + if err != nil { + return nil, err + } + + // If no sector numbers are specified, load all. + if snos == nil { + infos := make([]*SectorOnChainInfo, 0, sectors.Length()) + var info2 miner3.SectorOnChainInfo + if err := sectors.ForEach(&info2, func(_ int64) error { + info := fromV3SectorOnChainInfo(info2) + infos = append(infos, &info) + return nil + }); err != nil { + return nil, err + } + return infos, nil + } + + // Otherwise, load selected. + infos2, err := sectors.Load(*snos) + if err != nil { + return nil, err + } + infos := make([]*SectorOnChainInfo, len(infos2)) + for i, info2 := range infos2 { + info := fromV3SectorOnChainInfo(*info2) + infos[i] = &info + } + return infos, nil +} + +func (s *state3) IsAllocated(num abi.SectorNumber) (bool, error) { + var allocatedSectors bitfield.BitField + if err := s.store.Get(s.store.Context(), s.State.AllocatedSectors, &allocatedSectors); err != nil { + return false, err + } + + return allocatedSectors.IsSet(uint64(num)) +} + +func (s *state3) LoadDeadline(idx uint64) (Deadline, error) { + dls, err := s.State.LoadDeadlines(s.store) + if err != nil { + return nil, err + } + dl, err := dls.LoadDeadline(s.store, idx) + if err != nil { + return nil, err + } + return &deadline3{*dl, s.store}, nil +} + +func (s *state3) ForEachDeadline(cb func(uint64, Deadline) error) error { + dls, err := s.State.LoadDeadlines(s.store) + if err != nil { + return err + } + return dls.ForEach(s.store, func(i uint64, dl *miner3.Deadline) error { + return cb(i, &deadline3{*dl, s.store}) + }) +} + +func (s *state3) NumDeadlines() (uint64, error) { + return miner3.WPoStPeriodDeadlines, nil +} + +func (s *state3) DeadlinesChanged(other State) (bool, error) { + other2, ok := other.(*state3) + if !ok { + // treat an upgrade as a change, always + return true, nil + } + + return !s.State.Deadlines.Equals(other2.Deadlines), nil +} + +func (s *state3) MinerInfoChanged(other State) (bool, error) { + other0, ok := other.(*state3) + if !ok { + // treat an upgrade as a change, always + return true, nil + } + return !s.State.Info.Equals(other0.State.Info), nil +} + +func (s *state3) Info() (MinerInfo, error) { + info, err := s.State.GetInfo(s.store) + if err != nil { + return MinerInfo{}, err + } + + var pid *peer.ID + if peerID, err := peer.IDFromBytes(info.PeerId); err == nil { + pid = &peerID + } + + mi := MinerInfo{ + Owner: info.Owner, + Worker: info.Worker, + ControlAddresses: info.ControlAddresses, + + NewWorker: address.Undef, + WorkerChangeEpoch: -1, + + PeerId: pid, + Multiaddrs: info.Multiaddrs, + WindowPoStProofType: info.WindowPoStProofType, + SectorSize: info.SectorSize, + WindowPoStPartitionSectors: info.WindowPoStPartitionSectors, + ConsensusFaultElapsed: info.ConsensusFaultElapsed, + } + + if info.PendingWorkerKey != nil { + mi.NewWorker = info.PendingWorkerKey.NewWorker + mi.WorkerChangeEpoch = info.PendingWorkerKey.EffectiveAt + } + + return mi, nil +} + +func (s *state3) DeadlineInfo(epoch abi.ChainEpoch) (*dline.Info, error) { + return s.State.DeadlineInfo(epoch), nil +} + +func (s *state3) sectors() (adt.Array, error) { + return adt3.AsArray(s.store, s.Sectors, miner3.SectorsAmtBitwidth) +} + +func (s *state3) decodeSectorOnChainInfo(val *cbg.Deferred) (SectorOnChainInfo, error) { + var si miner3.SectorOnChainInfo + err := si.UnmarshalCBOR(bytes.NewReader(val.Raw)) + if err != nil { + return SectorOnChainInfo{}, err + } + + return fromV3SectorOnChainInfo(si), nil +} + +func (s *state3) precommits() (adt.Map, error) { + return adt3.AsMap(s.store, s.PreCommittedSectors, builtin3.DefaultHamtBitwidth) +} + +func (s *state3) decodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (SectorPreCommitOnChainInfo, error) { + var sp miner3.SectorPreCommitOnChainInfo + err := sp.UnmarshalCBOR(bytes.NewReader(val.Raw)) + if err != nil { + return SectorPreCommitOnChainInfo{}, err + } + + return fromV3SectorPreCommitOnChainInfo(sp), nil +} + +func (d *deadline3) LoadPartition(idx uint64) (Partition, error) { + p, err := d.Deadline.LoadPartition(d.store, idx) + if err != nil { + return nil, err + } + return &partition3{*p, d.store}, nil +} + +func (d *deadline3) ForEachPartition(cb func(uint64, Partition) error) error { + ps, err := d.Deadline.PartitionsArray(d.store) + if err != nil { + return err + } + var part miner3.Partition + return ps.ForEach(&part, func(i int64) error { + return cb(uint64(i), &partition3{part, d.store}) + }) +} + +func (d *deadline3) PartitionsChanged(other Deadline) (bool, error) { + other2, ok := other.(*deadline3) + if !ok { + // treat an upgrade as a change, always + return true, nil + } + + return !d.Deadline.Partitions.Equals(other2.Deadline.Partitions), nil +} + +func (d *deadline3) PartitionsPoSted() (bitfield.BitField, error) { + return d.Deadline.PartitionsPoSted, nil +} + +func (p *partition3) AllSectors() (bitfield.BitField, error) { + return p.Partition.Sectors, nil +} + +func (p *partition3) FaultySectors() (bitfield.BitField, error) { + return p.Partition.Faults, nil +} + +func (p *partition3) RecoveringSectors() (bitfield.BitField, error) { + return p.Partition.Recoveries, nil +} + +func fromV3SectorOnChainInfo(v3 miner3.SectorOnChainInfo) SectorOnChainInfo { + return SectorOnChainInfo{ + SectorNumber: v3.SectorNumber, + SealProof: v3.SealProof, + SealedCID: v3.SealedCID, + DealIDs: v3.DealIDs, + Activation: v3.Activation, + Expiration: v3.Expiration, + DealWeight: v3.DealWeight, + VerifiedDealWeight: v3.VerifiedDealWeight, + InitialPledge: v3.InitialPledge, + ExpectedDayReward: v3.ExpectedDayReward, + ExpectedStoragePledge: v3.ExpectedStoragePledge, + } +} + +func fromV3SectorPreCommitOnChainInfo(v3 miner3.SectorPreCommitOnChainInfo) SectorPreCommitOnChainInfo { + return SectorPreCommitOnChainInfo{ + Info: (SectorPreCommitInfo)(v3.Info), + PreCommitDeposit: v3.PreCommitDeposit, + PreCommitEpoch: v3.PreCommitEpoch, + DealWeight: v3.DealWeight, + VerifiedDealWeight: v3.VerifiedDealWeight, + } +} From 9d06a8b11656fc24359d8e192f76b896792e7560 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Sat, 16 Jan 2021 02:00:14 -0500 Subject: [PATCH 08/58] Add v3 actors support for multisig --- chain/actors/builtin/multisig/message.go | 2 + chain/actors/builtin/multisig/message3.go | 71 +++++++++++++++++ chain/actors/builtin/multisig/state.go | 4 + chain/actors/builtin/multisig/state3.go | 95 +++++++++++++++++++++++ 4 files changed, 172 insertions(+) create mode 100644 chain/actors/builtin/multisig/message3.go create mode 100644 chain/actors/builtin/multisig/state3.go diff --git a/chain/actors/builtin/multisig/message.go b/chain/actors/builtin/multisig/message.go index 3d2c66e6b..32f106ed2 100644 --- a/chain/actors/builtin/multisig/message.go +++ b/chain/actors/builtin/multisig/message.go @@ -24,6 +24,8 @@ func Message(version actors.Version, from address.Address) MessageBuilder { return message0{from} case actors.Version2: return message2{message0{from}} + case actors.Version3: + return message3{message0{from}} default: panic(fmt.Sprintf("unsupported actors version: %d", version)) } diff --git a/chain/actors/builtin/multisig/message3.go b/chain/actors/builtin/multisig/message3.go new file mode 100644 index 000000000..f5f6d8cdf --- /dev/null +++ b/chain/actors/builtin/multisig/message3.go @@ -0,0 +1,71 @@ +package multisig + +import ( + "golang.org/x/xerrors" + + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + + builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" + init3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/init" + multisig3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/multisig" + + "github.com/filecoin-project/lotus/chain/actors" + init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init" + "github.com/filecoin-project/lotus/chain/types" +) + +type message3 struct{ message0 } + +func (m message3) Create( + signers []address.Address, threshold uint64, + unlockStart, unlockDuration abi.ChainEpoch, + initialAmount abi.TokenAmount, +) (*types.Message, error) { + + lenAddrs := uint64(len(signers)) + + if lenAddrs < threshold { + return nil, xerrors.Errorf("cannot require signing of more addresses than provided for multisig") + } + + if threshold == 0 { + threshold = lenAddrs + } + + if m.from == address.Undef { + return nil, xerrors.Errorf("must provide source address") + } + + // Set up constructor parameters for multisig + msigParams := &multisig3.ConstructorParams{ + Signers: signers, + NumApprovalsThreshold: threshold, + UnlockDuration: unlockDuration, + StartEpoch: unlockStart, + } + + enc, actErr := actors.SerializeParams(msigParams) + if actErr != nil { + return nil, actErr + } + + // new actors are created by invoking 'exec' on the init actor with the constructor params + execParams := &init3.ExecParams{ + CodeCID: builtin3.MultisigActorCodeID, + ConstructorParams: enc, + } + + enc, actErr = actors.SerializeParams(execParams) + if actErr != nil { + return nil, actErr + } + + return &types.Message{ + To: init_.Address, + From: m.from, + Method: builtin3.MethodsInit.Exec, + Params: enc, + Value: initialAmount, + }, nil +} diff --git a/chain/actors/builtin/multisig/state.go b/chain/actors/builtin/multisig/state.go index fea42ba5f..cb3c84b22 100644 --- a/chain/actors/builtin/multisig/state.go +++ b/chain/actors/builtin/multisig/state.go @@ -12,6 +12,7 @@ import ( builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" msig0 "github.com/filecoin-project/specs-actors/actors/builtin/multisig" builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" + builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/actors/builtin" @@ -25,6 +26,9 @@ func init() { builtin.RegisterActorState(builtin2.MultisigActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { return load2(store, root) }) + builtin.RegisterActorState(builtin3.MultisigActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { + return load3(store, root) + }) } func Load(store adt.Store, act *types.Actor) (State, error) { diff --git a/chain/actors/builtin/multisig/state3.go b/chain/actors/builtin/multisig/state3.go new file mode 100644 index 000000000..7ade2ab64 --- /dev/null +++ b/chain/actors/builtin/multisig/state3.go @@ -0,0 +1,95 @@ +package multisig + +import ( + "bytes" + "encoding/binary" + + adt3 "github.com/filecoin-project/specs-actors/v3/actors/util/adt" + + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + "github.com/ipfs/go-cid" + cbg "github.com/whyrusleeping/cbor-gen" + "golang.org/x/xerrors" + + "github.com/filecoin-project/lotus/chain/actors/adt" + + builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" + msig3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/multisig" +) + +var _ State = (*state3)(nil) + +func load3(store adt.Store, root cid.Cid) (State, error) { + out := state3{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +type state3 struct { + msig3.State + store adt.Store +} + +func (s *state3) LockedBalance(currEpoch abi.ChainEpoch) (abi.TokenAmount, error) { + return s.State.AmountLocked(currEpoch - s.State.StartEpoch), nil +} + +func (s *state3) StartEpoch() (abi.ChainEpoch, error) { + return s.State.StartEpoch, nil +} + +func (s *state3) UnlockDuration() (abi.ChainEpoch, error) { + return s.State.UnlockDuration, nil +} + +func (s *state3) InitialBalance() (abi.TokenAmount, error) { + return s.State.InitialBalance, nil +} + +func (s *state3) Threshold() (uint64, error) { + return s.State.NumApprovalsThreshold, nil +} + +func (s *state3) Signers() ([]address.Address, error) { + return s.State.Signers, nil +} + +func (s *state3) ForEachPendingTxn(cb func(id int64, txn Transaction) error) error { + arr, err := adt3.AsMap(s.store, s.State.PendingTxns, builtin3.DefaultHamtBitwidth) + if err != nil { + return err + } + var out msig3.Transaction + return arr.ForEach(&out, func(key string) error { + txid, n := binary.Varint([]byte(key)) + if n <= 0 { + return xerrors.Errorf("invalid pending transaction key: %v", key) + } + return cb(txid, (Transaction)(out)) + }) +} + +func (s *state3) PendingTxnChanged(other State) (bool, error) { + other2, ok := other.(*state3) + if !ok { + // treat an upgrade as a change, always + return true, nil + } + return !s.State.PendingTxns.Equals(other2.PendingTxns), nil +} + +func (s *state3) transactions() (adt.Map, error) { + return adt3.AsMap(s.store, s.PendingTxns, builtin3.DefaultHamtBitwidth) +} + +func (s *state3) decodeTransaction(val *cbg.Deferred) (Transaction, error) { + var tx msig3.Transaction + if err := tx.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { + return Transaction{}, err + } + return tx, nil +} From abb388512eb797b5b70d57e5ca62eadcdd64536d Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Sat, 16 Jan 2021 02:09:19 -0500 Subject: [PATCH 09/58] Add v3 actors support for paych --- chain/actors/builtin/paych/message3.go | 74 ++++++++++++++++++ chain/actors/builtin/paych/state.go | 4 + chain/actors/builtin/paych/state3.go | 104 +++++++++++++++++++++++++ 3 files changed, 182 insertions(+) create mode 100644 chain/actors/builtin/paych/message3.go create mode 100644 chain/actors/builtin/paych/state3.go diff --git a/chain/actors/builtin/paych/message3.go b/chain/actors/builtin/paych/message3.go new file mode 100644 index 000000000..50503a140 --- /dev/null +++ b/chain/actors/builtin/paych/message3.go @@ -0,0 +1,74 @@ +package paych + +import ( + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + + builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" + init3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/init" + paych3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/paych" + + "github.com/filecoin-project/lotus/chain/actors" + init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init" + "github.com/filecoin-project/lotus/chain/types" +) + +type message3 struct{ from address.Address } + +func (m message3) Create(to address.Address, initialAmount abi.TokenAmount) (*types.Message, error) { + params, aerr := actors.SerializeParams(&paych3.ConstructorParams{From: m.from, To: to}) + if aerr != nil { + return nil, aerr + } + enc, aerr := actors.SerializeParams(&init3.ExecParams{ + CodeCID: builtin3.PaymentChannelActorCodeID, + ConstructorParams: params, + }) + if aerr != nil { + return nil, aerr + } + + return &types.Message{ + To: init_.Address, + From: m.from, + Value: initialAmount, + Method: builtin3.MethodsInit.Exec, + Params: enc, + }, nil +} + +func (m message3) Update(paych address.Address, sv *SignedVoucher, secret []byte) (*types.Message, error) { + params, aerr := actors.SerializeParams(&paych3.UpdateChannelStateParams{ + Sv: *sv, + Secret: secret, + }) + if aerr != nil { + return nil, aerr + } + + return &types.Message{ + To: paych, + From: m.from, + Value: abi.NewTokenAmount(0), + Method: builtin3.MethodsPaych.UpdateChannelState, + Params: params, + }, nil +} + +func (m message3) Settle(paych address.Address) (*types.Message, error) { + return &types.Message{ + To: paych, + From: m.from, + Value: abi.NewTokenAmount(0), + Method: builtin3.MethodsPaych.Settle, + }, nil +} + +func (m message3) Collect(paych address.Address) (*types.Message, error) { + return &types.Message{ + To: paych, + From: m.from, + Value: abi.NewTokenAmount(0), + Method: builtin3.MethodsPaych.Collect, + }, nil +} diff --git a/chain/actors/builtin/paych/state.go b/chain/actors/builtin/paych/state.go index 20c7a74b7..12c2616f1 100644 --- a/chain/actors/builtin/paych/state.go +++ b/chain/actors/builtin/paych/state.go @@ -15,6 +15,7 @@ import ( builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" paych0 "github.com/filecoin-project/specs-actors/actors/builtin/paych" builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" + builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/actors/builtin" @@ -28,6 +29,9 @@ func init() { builtin.RegisterActorState(builtin2.PaymentChannelActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { return load2(store, root) }) + builtin.RegisterActorState(builtin3.PaymentChannelActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { + return load3(store, root) + }) } // Load returns an abstract copy of payment channel state, irregardless of actor version diff --git a/chain/actors/builtin/paych/state3.go b/chain/actors/builtin/paych/state3.go new file mode 100644 index 000000000..14bb4cb61 --- /dev/null +++ b/chain/actors/builtin/paych/state3.go @@ -0,0 +1,104 @@ +package paych + +import ( + "github.com/ipfs/go-cid" + + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/go-state-types/big" + + "github.com/filecoin-project/lotus/chain/actors/adt" + + paych3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/paych" + adt3 "github.com/filecoin-project/specs-actors/v3/actors/util/adt" +) + +var _ State = (*state3)(nil) + +func load3(store adt.Store, root cid.Cid) (State, error) { + out := state3{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +type state3 struct { + paych3.State + store adt.Store + lsAmt *adt3.Array +} + +// Channel owner, who has funded the actor +func (s *state3) From() (address.Address, error) { + return s.State.From, nil +} + +// Recipient of payouts from channel +func (s *state3) To() (address.Address, error) { + return s.State.To, nil +} + +// Height at which the channel can be `Collected` +func (s *state3) SettlingAt() (abi.ChainEpoch, error) { + return s.State.SettlingAt, nil +} + +// Amount successfully redeemed through the payment channel, paid out on `Collect()` +func (s *state3) ToSend() (abi.TokenAmount, error) { + return s.State.ToSend, nil +} + +func (s *state3) getOrLoadLsAmt() (*adt3.Array, error) { + if s.lsAmt != nil { + return s.lsAmt, nil + } + + // Get the lane state from the chain + lsamt, err := adt3.AsArray(s.store, s.State.LaneStates, paych3.LaneStatesAmtBitwidth) + if err != nil { + return nil, err + } + + s.lsAmt = lsamt + return lsamt, nil +} + +// Get total number of lanes +func (s *state3) LaneCount() (uint64, error) { + lsamt, err := s.getOrLoadLsAmt() + if err != nil { + return 0, err + } + return lsamt.Length(), nil +} + +// Iterate lane states +func (s *state3) ForEachLaneState(cb func(idx uint64, dl LaneState) error) error { + // Get the lane state from the chain + lsamt, err := s.getOrLoadLsAmt() + if err != nil { + return err + } + + // Note: we use a map instead of an array to store laneStates because the + // client sets the lane ID (the index) and potentially they could use a + // very large index. + var ls paych3.LaneState + return lsamt.ForEach(&ls, func(i int64) error { + return cb(uint64(i), &laneState3{ls}) + }) +} + +type laneState3 struct { + paych3.LaneState +} + +func (ls *laneState3) Redeemed() (big.Int, error) { + return ls.LaneState.Redeemed, nil +} + +func (ls *laneState3) Nonce() (uint64, error) { + return ls.LaneState.Nonce, nil +} From ee99e68614550aea56b18bd7e8f313d132a2de7a Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Sat, 16 Jan 2021 02:39:35 -0500 Subject: [PATCH 10/58] Add v3 actors support for power --- chain/actors/builtin/builtin.go | 9 +- chain/actors/builtin/power/power.go | 4 + chain/actors/builtin/power/v3.go | 149 ++++++++++++++++++++++++++++ 3 files changed, 160 insertions(+), 2 deletions(-) create mode 100644 chain/actors/builtin/power/v3.go diff --git a/chain/actors/builtin/builtin.go b/chain/actors/builtin/builtin.go index afba8efe8..3f3488543 100644 --- a/chain/actors/builtin/builtin.go +++ b/chain/actors/builtin/builtin.go @@ -18,6 +18,7 @@ import ( miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" proof0 "github.com/filecoin-project/specs-actors/actors/runtime/proof" smoothing0 "github.com/filecoin-project/specs-actors/actors/util/smoothing" + smoothing3 "github.com/filecoin-project/specs-actors/v3/actors/util/smoothing" ) var SystemActorAddr = builtin0.SystemActorAddr @@ -56,8 +57,12 @@ func QAPowerForWeight(size abi.SectorSize, duration abi.ChainEpoch, dealWeight, return miner0.QAPowerForWeight(size, duration, dealWeight, verifiedWeight) } -func FromV2FilterEstimate(v1 smoothing2.FilterEstimate) FilterEstimate { - return (FilterEstimate)(v1) +func FromV2FilterEstimate(v2 smoothing2.FilterEstimate) FilterEstimate { + return (FilterEstimate)(v2) +} + +func FromV3FilterEstimate(v3 smoothing3.FilterEstimate) FilterEstimate { + return (FilterEstimate)(v3) } type ActorStateLoader func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) diff --git a/chain/actors/builtin/power/power.go b/chain/actors/builtin/power/power.go index e0cf0d700..c6feefef9 100644 --- a/chain/actors/builtin/power/power.go +++ b/chain/actors/builtin/power/power.go @@ -16,6 +16,7 @@ import ( builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" + builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" ) func init() { @@ -25,6 +26,9 @@ func init() { builtin.RegisterActorState(builtin2.StoragePowerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { return load2(store, root) }) + builtin.RegisterActorState(builtin3.StoragePowerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { + return load3(store, root) + }) } var ( diff --git a/chain/actors/builtin/power/v3.go b/chain/actors/builtin/power/v3.go new file mode 100644 index 000000000..6d7ce82ec --- /dev/null +++ b/chain/actors/builtin/power/v3.go @@ -0,0 +1,149 @@ +package power + +import ( + "bytes" + + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + "github.com/ipfs/go-cid" + cbg "github.com/whyrusleeping/cbor-gen" + + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/actors/builtin" + + builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" + power3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/power" + adt3 "github.com/filecoin-project/specs-actors/v3/actors/util/adt" +) + +var _ State = (*state3)(nil) + +func load3(store adt.Store, root cid.Cid) (State, error) { + out := state3{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +type state3 struct { + power3.State + store adt.Store +} + +func (s *state3) TotalLocked() (abi.TokenAmount, error) { + return s.TotalPledgeCollateral, nil +} + +func (s *state3) TotalPower() (Claim, error) { + return Claim{ + RawBytePower: s.TotalRawBytePower, + QualityAdjPower: s.TotalQualityAdjPower, + }, nil +} + +// Committed power to the network. Includes miners below the minimum threshold. +func (s *state3) TotalCommitted() (Claim, error) { + return Claim{ + RawBytePower: s.TotalBytesCommitted, + QualityAdjPower: s.TotalQABytesCommitted, + }, nil +} + +func (s *state3) MinerPower(addr address.Address) (Claim, bool, error) { + claims, err := adt3.AsMap(s.store, s.Claims, builtin3.DefaultHamtBitwidth) + if err != nil { + return Claim{}, false, err + } + var claim power3.Claim + ok, err := claims.Get(abi.AddrKey(addr), &claim) + if err != nil { + return Claim{}, false, err + } + return Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }, ok, nil +} + +func (s *state3) MinerNominalPowerMeetsConsensusMinimum(a address.Address) (bool, error) { + return s.State.MinerNominalPowerMeetsConsensusMinimum(s.store, a) +} + +func (s *state3) TotalPowerSmoothed() (builtin.FilterEstimate, error) { + return builtin.FromV3FilterEstimate(s.State.ThisEpochQAPowerSmoothed), nil +} + +func (s *state3) MinerCounts() (uint64, uint64, error) { + return uint64(s.State.MinerAboveMinPowerCount), uint64(s.State.MinerCount), nil +} + +func (s *state3) ListAllMiners() ([]address.Address, error) { + claims, err := s.claims() + if err != nil { + return nil, err + } + + var miners []address.Address + err = claims.ForEach(nil, func(k string) error { + a, err := address.NewFromBytes([]byte(k)) + if err != nil { + return err + } + miners = append(miners, a) + return nil + }) + if err != nil { + return nil, err + } + + return miners, nil +} + +func (s *state3) ForEachClaim(cb func(miner address.Address, claim Claim) error) error { + claims, err := s.claims() + if err != nil { + return err + } + + var claim power3.Claim + return claims.ForEach(&claim, func(k string) error { + a, err := address.NewFromBytes([]byte(k)) + if err != nil { + return err + } + return cb(a, Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }) + }) +} + +func (s *state3) ClaimsChanged(other State) (bool, error) { + other2, ok := other.(*state3) + if !ok { + // treat an upgrade as a change, always + return true, nil + } + return !s.State.Claims.Equals(other2.State.Claims), nil +} + +func (s *state3) claims() (adt.Map, error) { + return adt3.AsMap(s.store, s.Claims, builtin3.DefaultHamtBitwidth) +} + +func (s *state3) decodeClaim(val *cbg.Deferred) (Claim, error) { + var ci power3.Claim + if err := ci.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { + return Claim{}, err + } + return fromV3Claim(ci), nil +} + +func fromV3Claim(v3 power3.Claim) Claim { + return Claim{ + RawBytePower: v3.RawBytePower, + QualityAdjPower: v3.QualityAdjPower, + } +} From 76abbb89389e4a7a9b83e20b0b0275327cf00758 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Sat, 16 Jan 2021 02:41:32 -0500 Subject: [PATCH 11/58] Add v3 actors support for reward --- chain/actors/builtin/reward/reward.go | 4 ++ chain/actors/builtin/reward/v3.go | 86 +++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 chain/actors/builtin/reward/v3.go diff --git a/chain/actors/builtin/reward/reward.go b/chain/actors/builtin/reward/reward.go index 952ca270b..aeb2321ab 100644 --- a/chain/actors/builtin/reward/reward.go +++ b/chain/actors/builtin/reward/reward.go @@ -9,6 +9,7 @@ import ( "github.com/filecoin-project/go-state-types/cbor" builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" + builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/actors/builtin" @@ -22,6 +23,9 @@ func init() { builtin.RegisterActorState(builtin2.RewardActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { return load2(store, root) }) + builtin.RegisterActorState(builtin3.RewardActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { + return load3(store, root) + }) } var ( diff --git a/chain/actors/builtin/reward/v3.go b/chain/actors/builtin/reward/v3.go new file mode 100644 index 000000000..18bd58f8e --- /dev/null +++ b/chain/actors/builtin/reward/v3.go @@ -0,0 +1,86 @@ +package reward + +import ( + "github.com/filecoin-project/go-state-types/abi" + "github.com/ipfs/go-cid" + + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/actors/builtin" + + miner3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/miner" + reward3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/reward" + smoothing3 "github.com/filecoin-project/specs-actors/v3/actors/util/smoothing" +) + +var _ State = (*state3)(nil) + +func load3(store adt.Store, root cid.Cid) (State, error) { + out := state3{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +type state3 struct { + reward3.State + store adt.Store +} + +func (s *state3) ThisEpochReward() (abi.TokenAmount, error) { + return s.State.ThisEpochReward, nil +} + +func (s *state3) ThisEpochRewardSmoothed() (builtin.FilterEstimate, error) { + return builtin.FilterEstimate{ + PositionEstimate: s.State.ThisEpochRewardSmoothed.PositionEstimate, + VelocityEstimate: s.State.ThisEpochRewardSmoothed.VelocityEstimate, + }, nil +} + +func (s *state3) ThisEpochBaselinePower() (abi.StoragePower, error) { + return s.State.ThisEpochBaselinePower, nil +} + +func (s *state3) TotalStoragePowerReward() (abi.TokenAmount, error) { + return s.State.TotalStoragePowerReward, nil +} + +func (s *state3) EffectiveBaselinePower() (abi.StoragePower, error) { + return s.State.EffectiveBaselinePower, nil +} + +func (s *state3) EffectiveNetworkTime() (abi.ChainEpoch, error) { + return s.State.EffectiveNetworkTime, nil +} + +func (s *state3) CumsumBaseline() (reward3.Spacetime, error) { + return s.State.CumsumBaseline, nil +} + +func (s *state3) CumsumRealized() (reward3.Spacetime, error) { + return s.State.CumsumRealized, nil +} + +func (s *state3) InitialPledgeForPower(qaPower abi.StoragePower, networkTotalPledge abi.TokenAmount, networkQAPower *builtin.FilterEstimate, circSupply abi.TokenAmount) (abi.TokenAmount, error) { + return miner3.InitialPledgeForPower( + qaPower, + s.State.ThisEpochBaselinePower, + s.State.ThisEpochRewardSmoothed, + smoothing3.FilterEstimate{ + PositionEstimate: networkQAPower.PositionEstimate, + VelocityEstimate: networkQAPower.VelocityEstimate, + }, + circSupply, + ), nil +} + +func (s *state3) PreCommitDepositForPower(networkQAPower builtin.FilterEstimate, sectorWeight abi.StoragePower) (abi.TokenAmount, error) { + return miner3.PreCommitDepositForPower(s.State.ThisEpochRewardSmoothed, + smoothing3.FilterEstimate{ + PositionEstimate: networkQAPower.PositionEstimate, + VelocityEstimate: networkQAPower.VelocityEstimate, + }, + sectorWeight), nil +} From 06f13f8e00c9627b8b46839bbeba0abed53ff57c Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Sat, 16 Jan 2021 02:42:59 -0500 Subject: [PATCH 12/58] Add v3 actors support for verifreg --- chain/actors/builtin/verifreg/v3.go | 48 +++++++++++++++++++++++ chain/actors/builtin/verifreg/verifreg.go | 4 ++ 2 files changed, 52 insertions(+) create mode 100644 chain/actors/builtin/verifreg/v3.go diff --git a/chain/actors/builtin/verifreg/v3.go b/chain/actors/builtin/verifreg/v3.go new file mode 100644 index 000000000..4667412c5 --- /dev/null +++ b/chain/actors/builtin/verifreg/v3.go @@ -0,0 +1,48 @@ +package verifreg + +import ( + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + "github.com/ipfs/go-cid" + + "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/lotus/chain/actors/adt" + + verifreg3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/verifreg" +) + +var _ State = (*state3)(nil) + +func load3(store adt.Store, root cid.Cid) (State, error) { + out := state3{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +type state3 struct { + verifreg3.State + store adt.Store +} + +func (s *state3) RootKey() (address.Address, error) { + return s.State.RootKey, nil +} + +func (s *state3) VerifiedClientDataCap(addr address.Address) (bool, abi.StoragePower, error) { + return getDataCap(s.store, actors.Version3, s.State.VerifiedClients, addr) +} + +func (s *state3) VerifierDataCap(addr address.Address) (bool, abi.StoragePower, error) { + return getDataCap(s.store, actors.Version3, s.State.Verifiers, addr) +} + +func (s *state3) ForEachVerifier(cb func(addr address.Address, dcap abi.StoragePower) error) error { + return forEachCap(s.store, actors.Version3, s.State.Verifiers, cb) +} + +func (s *state3) ForEachClient(cb func(addr address.Address, dcap abi.StoragePower) error) error { + return forEachCap(s.store, actors.Version3, s.State.VerifiedClients, cb) +} diff --git a/chain/actors/builtin/verifreg/verifreg.go b/chain/actors/builtin/verifreg/verifreg.go index a4468d8a0..9176c4978 100644 --- a/chain/actors/builtin/verifreg/verifreg.go +++ b/chain/actors/builtin/verifreg/verifreg.go @@ -3,6 +3,7 @@ package verifreg import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" "github.com/ipfs/go-cid" "golang.org/x/xerrors" @@ -22,6 +23,9 @@ func init() { builtin.RegisterActorState(builtin2.VerifiedRegistryActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { return load2(store, root) }) + builtin.RegisterActorState(builtin3.VerifiedRegistryActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { + return load3(store, root) + }) } var ( From 9ce63c1211f09061d9f1c00c44ebf0033c8ecf81 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 18 Jan 2021 14:56:22 -0800 Subject: [PATCH 13/58] simplify v3 claims map access --- chain/actors/builtin/power/v3.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chain/actors/builtin/power/v3.go b/chain/actors/builtin/power/v3.go index 6d7ce82ec..fd161dda5 100644 --- a/chain/actors/builtin/power/v3.go +++ b/chain/actors/builtin/power/v3.go @@ -52,7 +52,7 @@ func (s *state3) TotalCommitted() (Claim, error) { } func (s *state3) MinerPower(addr address.Address) (Claim, bool, error) { - claims, err := adt3.AsMap(s.store, s.Claims, builtin3.DefaultHamtBitwidth) + claims, err := s.claims() if err != nil { return Claim{}, false, err } From be1f15052cb177821cb6f25aaec6ca6b5e505ff3 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 18 Jan 2021 15:01:44 -0800 Subject: [PATCH 14/58] register remaining state decoders --- chain/actors/builtin/account/account.go | 3 +++ chain/actors/builtin/init/init.go | 3 +++ chain/actors/builtin/market/market.go | 3 +++ 3 files changed, 9 insertions(+) diff --git a/chain/actors/builtin/account/account.go b/chain/actors/builtin/account/account.go index c77d5b540..8c8af8ae3 100644 --- a/chain/actors/builtin/account/account.go +++ b/chain/actors/builtin/account/account.go @@ -23,6 +23,9 @@ func init() { builtin.RegisterActorState(builtin2.AccountActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { return load2(store, root) }) + builtin.RegisterActorState(builtin3.AccountActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { + return load3(store, root) + }) } var Methods = builtin2.MethodsAccount diff --git a/chain/actors/builtin/init/init.go b/chain/actors/builtin/init/init.go index 7635117cd..2d5090a48 100644 --- a/chain/actors/builtin/init/init.go +++ b/chain/actors/builtin/init/init.go @@ -25,6 +25,9 @@ func init() { builtin.RegisterActorState(builtin2.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { return load2(store, root) }) + builtin.RegisterActorState(builtin3.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { + return load3(store, root) + }) } var ( diff --git a/chain/actors/builtin/market/market.go b/chain/actors/builtin/market/market.go index 49ad06436..94514f4d6 100644 --- a/chain/actors/builtin/market/market.go +++ b/chain/actors/builtin/market/market.go @@ -26,6 +26,9 @@ func init() { builtin.RegisterActorState(builtin2.StorageMarketActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { return load2(store, root) }) + builtin.RegisterActorState(builtin3.StorageMarketActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { + return load3(store, root) + }) } var ( From 95c57d0ce37348b338fc325f65c44cd08e070d5a Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 18 Jan 2021 15:04:32 -0800 Subject: [PATCH 15/58] and actually hook up loading logic --- chain/actors/builtin/miner/miner.go | 2 ++ chain/actors/builtin/multisig/state.go | 2 ++ chain/actors/builtin/paych/state.go | 2 ++ chain/actors/builtin/power/power.go | 2 ++ chain/actors/builtin/reward/reward.go | 2 ++ chain/actors/builtin/verifreg/verifreg.go | 2 ++ 6 files changed, 12 insertions(+) diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index e520e07d5..398e0ba34 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -57,6 +57,8 @@ func Load(store adt.Store, act *types.Actor) (st State, err error) { return load0(store, act.Head) case builtin2.StorageMinerActorCodeID: return load2(store, act.Head) + case builtin3.StorageMinerActorCodeID: + return load3(store, act.Head) } return nil, xerrors.Errorf("unknown actor code %s", act.Code) } diff --git a/chain/actors/builtin/multisig/state.go b/chain/actors/builtin/multisig/state.go index cb3c84b22..5f9fb6a52 100644 --- a/chain/actors/builtin/multisig/state.go +++ b/chain/actors/builtin/multisig/state.go @@ -37,6 +37,8 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return load0(store, act.Head) case builtin2.MultisigActorCodeID: return load2(store, act.Head) + case builtin3.MultisigActorCodeID: + return load3(store, act.Head) } return nil, xerrors.Errorf("unknown actor code %s", act.Code) } diff --git a/chain/actors/builtin/paych/state.go b/chain/actors/builtin/paych/state.go index 12c2616f1..accb96244 100644 --- a/chain/actors/builtin/paych/state.go +++ b/chain/actors/builtin/paych/state.go @@ -41,6 +41,8 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return load0(store, act.Head) case builtin2.PaymentChannelActorCodeID: return load2(store, act.Head) + case builtin3.PaymentChannelActorCodeID: + return load3(store, act.Head) } return nil, xerrors.Errorf("unknown actor code %s", act.Code) } diff --git a/chain/actors/builtin/power/power.go b/chain/actors/builtin/power/power.go index c6feefef9..959841381 100644 --- a/chain/actors/builtin/power/power.go +++ b/chain/actors/builtin/power/power.go @@ -42,6 +42,8 @@ func Load(store adt.Store, act *types.Actor) (st State, err error) { return load0(store, act.Head) case builtin2.StoragePowerActorCodeID: return load2(store, act.Head) + case builtin3.StoragePowerActorCodeID: + return load3(store, act.Head) } return nil, xerrors.Errorf("unknown actor code %s", act.Code) } diff --git a/chain/actors/builtin/reward/reward.go b/chain/actors/builtin/reward/reward.go index aeb2321ab..a3dc29558 100644 --- a/chain/actors/builtin/reward/reward.go +++ b/chain/actors/builtin/reward/reward.go @@ -39,6 +39,8 @@ func Load(store adt.Store, act *types.Actor) (st State, err error) { return load0(store, act.Head) case builtin2.RewardActorCodeID: return load2(store, act.Head) + case builtin3.RewardActorCodeID: + return load3(store, act.Head) } return nil, xerrors.Errorf("unknown actor code %s", act.Code) } diff --git a/chain/actors/builtin/verifreg/verifreg.go b/chain/actors/builtin/verifreg/verifreg.go index 9176c4978..9f943e711 100644 --- a/chain/actors/builtin/verifreg/verifreg.go +++ b/chain/actors/builtin/verifreg/verifreg.go @@ -39,6 +39,8 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return load0(store, act.Head) case builtin2.VerifiedRegistryActorCodeID: return load2(store, act.Head) + case builtin3.VerifiedRegistryActorCodeID: + return load3(store, act.Head) } return nil, xerrors.Errorf("unknown actor code %s", act.Code) } From c31f5130e3c8d3ba471337374fae921f0071a48b Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 18 Jan 2021 15:10:03 -0800 Subject: [PATCH 16/58] update imports to v3 --- chain/actors/builtin/account/account.go | 2 +- chain/actors/builtin/builtin.go | 7 ++++--- chain/actors/builtin/cron/cron.go | 6 +++--- chain/actors/builtin/init/init.go | 4 ++-- chain/actors/builtin/market/market.go | 4 ++-- chain/actors/builtin/miner/miner.go | 2 +- chain/actors/builtin/multisig/message.go | 12 ++++++------ chain/actors/builtin/multisig/state0.go | 2 +- chain/actors/builtin/paych/message.go | 4 ++-- chain/actors/builtin/power/power.go | 4 ++-- chain/actors/builtin/reward/reward.go | 4 ++-- chain/actors/builtin/verifreg/verifreg.go | 4 ++-- 12 files changed, 28 insertions(+), 27 deletions(-) diff --git a/chain/actors/builtin/account/account.go b/chain/actors/builtin/account/account.go index 8c8af8ae3..53a03e6f3 100644 --- a/chain/actors/builtin/account/account.go +++ b/chain/actors/builtin/account/account.go @@ -28,7 +28,7 @@ func init() { }) } -var Methods = builtin2.MethodsAccount +var Methods = builtin3.MethodsAccount func Load(store adt.Store, act *types.Actor) (State, error) { switch act.Code { diff --git a/chain/actors/builtin/builtin.go b/chain/actors/builtin/builtin.go index 3f3488543..2d4c47a29 100644 --- a/chain/actors/builtin/builtin.go +++ b/chain/actors/builtin/builtin.go @@ -2,12 +2,13 @@ package builtin import ( "github.com/filecoin-project/go-address" - builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" smoothing2 "github.com/filecoin-project/specs-actors/v2/actors/util/smoothing" "github.com/ipfs/go-cid" "golang.org/x/xerrors" builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" + builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" + builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/cbor" @@ -39,8 +40,8 @@ const ( ) const ( - MethodSend = builtin2.MethodSend - MethodConstructor = builtin2.MethodConstructor + MethodSend = builtin3.MethodSend + MethodConstructor = builtin3.MethodConstructor ) // TODO: Why does actors have 2 different versions of this? diff --git a/chain/actors/builtin/cron/cron.go b/chain/actors/builtin/cron/cron.go index 65bfd992f..284aad82e 100644 --- a/chain/actors/builtin/cron/cron.go +++ b/chain/actors/builtin/cron/cron.go @@ -1,10 +1,10 @@ package cron import ( - builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" + builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" ) var ( - Address = builtin2.CronActorAddr - Methods = builtin2.MethodsCron + Address = builtin3.CronActorAddr + Methods = builtin3.MethodsCron ) diff --git a/chain/actors/builtin/init/init.go b/chain/actors/builtin/init/init.go index 2d5090a48..f9e912768 100644 --- a/chain/actors/builtin/init/init.go +++ b/chain/actors/builtin/init/init.go @@ -31,8 +31,8 @@ func init() { } var ( - Address = builtin2.InitActorAddr - Methods = builtin2.MethodsInit + Address = builtin3.InitActorAddr + Methods = builtin3.MethodsInit ) func Load(store adt.Store, act *types.Actor) (State, error) { diff --git a/chain/actors/builtin/market/market.go b/chain/actors/builtin/market/market.go index 94514f4d6..628b27e08 100644 --- a/chain/actors/builtin/market/market.go +++ b/chain/actors/builtin/market/market.go @@ -32,8 +32,8 @@ func init() { } var ( - Address = builtin2.StorageMarketActorAddr - Methods = builtin2.MethodsMarket + Address = builtin3.StorageMarketActorAddr + Methods = builtin3.MethodsMarket ) func Load(store adt.Store, act *types.Actor) (st State, err error) { diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index 398e0ba34..279ca5e50 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -36,7 +36,7 @@ func init() { }) } -var Methods = builtin2.MethodsMiner +var Methods = builtin3.MethodsMiner // Unchanged between v0, v2, and v3 actors var WPoStProvingPeriod = miner0.WPoStProvingPeriod diff --git a/chain/actors/builtin/multisig/message.go b/chain/actors/builtin/multisig/message.go index 32f106ed2..a43b919aa 100644 --- a/chain/actors/builtin/multisig/message.go +++ b/chain/actors/builtin/multisig/message.go @@ -9,14 +9,14 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" - builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" - multisig2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/multisig" + builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" + multisig3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/multisig" "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/types" ) -var Methods = builtin2.MethodsMultisig +var Methods = builtin3.MethodsMultisig func Message(version actors.Version, from address.Address) MessageBuilder { switch version { @@ -49,11 +49,11 @@ type MessageBuilder interface { } // this type is the same between v0 and v2 -type ProposalHashData = multisig2.ProposalHashData -type ProposeReturn = multisig2.ProposeReturn +type ProposalHashData = multisig3.ProposalHashData +type ProposeReturn = multisig3.ProposeReturn func txnParams(id uint64, data *ProposalHashData) ([]byte, error) { - params := multisig2.TxnIDParams{ID: multisig2.TxnID(id)} + params := multisig3.TxnIDParams{ID: multisig3.TxnID(id)} if data != nil { if data.Requester.Protocol() != address.ID { return nil, xerrors.Errorf("proposer address must be an ID address, was %s", data.Requester) diff --git a/chain/actors/builtin/multisig/state0.go b/chain/actors/builtin/multisig/state0.go index e6f9a9c36..5548b0a5c 100644 --- a/chain/actors/builtin/multisig/state0.go +++ b/chain/actors/builtin/multisig/state0.go @@ -13,8 +13,8 @@ import ( "github.com/filecoin-project/lotus/chain/actors/adt" msig0 "github.com/filecoin-project/specs-actors/actors/builtin/multisig" + multisig0 "github.com/filecoin-project/specs-actors/actors/builtin/multisig" adt0 "github.com/filecoin-project/specs-actors/actors/util/adt" - multisig0 "github.com/filecoin-project/specs-actors/v2/actors/builtin/multisig" ) var _ State = (*state0)(nil) diff --git a/chain/actors/builtin/paych/message.go b/chain/actors/builtin/paych/message.go index 5709d4b23..cfc8cbe71 100644 --- a/chain/actors/builtin/paych/message.go +++ b/chain/actors/builtin/paych/message.go @@ -8,10 +8,10 @@ import ( "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/types" - builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" + builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" ) -var Methods = builtin2.MethodsPaych +var Methods = builtin3.MethodsPaych func Message(version actors.Version, from address.Address) MessageBuilder { switch version { diff --git a/chain/actors/builtin/power/power.go b/chain/actors/builtin/power/power.go index 959841381..712fb0b98 100644 --- a/chain/actors/builtin/power/power.go +++ b/chain/actors/builtin/power/power.go @@ -32,8 +32,8 @@ func init() { } var ( - Address = builtin2.StoragePowerActorAddr - Methods = builtin2.MethodsPower + Address = builtin3.StoragePowerActorAddr + Methods = builtin3.MethodsPower ) func Load(store adt.Store, act *types.Actor) (st State, err error) { diff --git a/chain/actors/builtin/reward/reward.go b/chain/actors/builtin/reward/reward.go index a3dc29558..156b3ec55 100644 --- a/chain/actors/builtin/reward/reward.go +++ b/chain/actors/builtin/reward/reward.go @@ -29,8 +29,8 @@ func init() { } var ( - Address = builtin2.RewardActorAddr - Methods = builtin2.MethodsReward + Address = builtin3.RewardActorAddr + Methods = builtin3.MethodsReward ) func Load(store adt.Store, act *types.Actor) (st State, err error) { diff --git a/chain/actors/builtin/verifreg/verifreg.go b/chain/actors/builtin/verifreg/verifreg.go index 9f943e711..4e3f3559b 100644 --- a/chain/actors/builtin/verifreg/verifreg.go +++ b/chain/actors/builtin/verifreg/verifreg.go @@ -29,8 +29,8 @@ func init() { } var ( - Address = builtin2.VerifiedRegistryActorAddr - Methods = builtin2.MethodsVerifiedRegistry + Address = builtin3.VerifiedRegistryActorAddr + Methods = builtin3.MethodsVerifiedRegistry ) func Load(store adt.Store, act *types.Actor) (State, error) { From 7882b0163b2c8517d713f0f87daf608dfbd4f621 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 18 Jan 2021 15:15:18 -0800 Subject: [PATCH 17/58] update actor "is" functions for v3 --- chain/actors/builtin/builtin.go | 34 +++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/chain/actors/builtin/builtin.go b/chain/actors/builtin/builtin.go index 2d4c47a29..1e535dca4 100644 --- a/chain/actors/builtin/builtin.go +++ b/chain/actors/builtin/builtin.go @@ -2,7 +2,6 @@ package builtin import ( "github.com/filecoin-project/go-address" - smoothing2 "github.com/filecoin-project/specs-actors/v2/actors/util/smoothing" "github.com/ipfs/go-cid" "golang.org/x/xerrors" @@ -16,10 +15,12 @@ import ( "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/types" + smoothing0 "github.com/filecoin-project/specs-actors/actors/util/smoothing" + smoothing2 "github.com/filecoin-project/specs-actors/v2/actors/util/smoothing" + smoothing3 "github.com/filecoin-project/specs-actors/v3/actors/util/smoothing" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" proof0 "github.com/filecoin-project/specs-actors/actors/runtime/proof" - smoothing0 "github.com/filecoin-project/specs-actors/actors/util/smoothing" - smoothing3 "github.com/filecoin-project/specs-actors/v3/actors/util/smoothing" ) var SystemActorAddr = builtin0.SystemActorAddr @@ -44,7 +45,8 @@ const ( MethodConstructor = builtin3.MethodConstructor ) -// TODO: Why does actors have 2 different versions of this? +// These are all just type aliases across actor versions 0, 2, & 3. In the future, that might change +// and we might need to do something fancier. type SectorInfo = proof0.SectorInfo type PoStProof = proof0.PoStProof type FilterEstimate = smoothing0.FilterEstimate @@ -53,7 +55,7 @@ func FromV0FilterEstimate(v0 smoothing0.FilterEstimate) FilterEstimate { return (FilterEstimate)(v0) } -// Doesn't change between actors v0 and v1 +// Doesn't change between actors v0, v2, and v3. func QAPowerForWeight(size abi.SectorSize, duration abi.ChainEpoch, dealWeight, verifiedWeight abi.DealWeight) abi.StoragePower { return miner0.QAPowerForWeight(size, duration, dealWeight, verifiedWeight) } @@ -88,30 +90,42 @@ func ActorNameByCode(c cid.Cid) string { return builtin0.ActorNameByCode(c) case builtin2.IsBuiltinActor(c): return builtin2.ActorNameByCode(c) + case builtin3.IsBuiltinActor(c): + return builtin3.ActorNameByCode(c) default: return "" } } func IsBuiltinActor(c cid.Cid) bool { - return builtin0.IsBuiltinActor(c) || builtin2.IsBuiltinActor(c) + return builtin0.IsBuiltinActor(c) || + builtin2.IsBuiltinActor(c) || + builtin3.IsBuiltinActor(c) } func IsAccountActor(c cid.Cid) bool { - return c == builtin0.AccountActorCodeID || c == builtin2.AccountActorCodeID + return c == builtin0.AccountActorCodeID || + c == builtin2.AccountActorCodeID || + c == builtin3.AccountActorCodeID } func IsStorageMinerActor(c cid.Cid) bool { - return c == builtin0.StorageMinerActorCodeID || c == builtin2.StorageMinerActorCodeID + return c == builtin0.StorageMinerActorCodeID || + c == builtin2.StorageMinerActorCodeID || + c == builtin3.StorageMinerActorCodeID } func IsMultisigActor(c cid.Cid) bool { - return c == builtin0.MultisigActorCodeID || c == builtin2.MultisigActorCodeID + return c == builtin0.MultisigActorCodeID || + c == builtin2.MultisigActorCodeID || + c == builtin3.MultisigActorCodeID } func IsPaymentChannelActor(c cid.Cid) bool { - return c == builtin0.PaymentChannelActorCodeID || c == builtin2.PaymentChannelActorCodeID + return c == builtin0.PaymentChannelActorCodeID || + c == builtin2.PaymentChannelActorCodeID || + c == builtin3.PaymentChannelActorCodeID } func makeAddress(addr string) address.Address { From 4de56d5eacbcea1696c2934f5f88eef6d48357c3 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 18 Jan 2021 15:23:28 -0800 Subject: [PATCH 18/58] docsgen --- documentation/en/api-methods.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/en/api-methods.md b/documentation/en/api-methods.md index dbac8e30f..2c75ecaaa 100644 --- a/documentation/en/api-methods.md +++ b/documentation/en/api-methods.md @@ -4028,7 +4028,7 @@ Response: "WorkerChangeEpoch": 10101, "PeerId": "12D3KooWGzxzKZYveHXtpG6AsrUJBcWxHBFS2HsEoGTxrMLvKXtf", "Multiaddrs": null, - "SealProofType": 8, + "WindowPoStProofType": 8, "SectorSize": 34359738368, "WindowPoStPartitionSectors": 42, "ConsensusFaultElapsed": 10101 From c05df6dc1de1c8fe1b168655929eb30c7ef97ba8 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 18 Jan 2021 17:44:16 -0800 Subject: [PATCH 19/58] fix: use the correct proof type in winning proofs --- chain/stmgr/utils.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index ce0384842..f7ed4c2e3 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -212,7 +212,24 @@ func GetSectorsForWinningPoSt(ctx context.Context, nv network.Version, pv ffiwra return nil, xerrors.Errorf("getting miner ID: %w", err) } - ids, err := pv.GenerateWinningPoStSectorChallenge(ctx, info.WindowPoStProofType, abi.ActorID(mid), rand, numProvSect) + // TODO: move this to somewhere in specs-actors or the state types. + var proofType abi.RegisteredPoStProof + switch info.WindowPoStProofType { + case abi.RegisteredPoStProof_StackedDrgWinning2KiBV1: + proofType = abi.RegisteredPoStProof_StackedDrgWindow2KiBV1 + case abi.RegisteredPoStProof_StackedDrgWinning8MiBV1: + proofType = abi.RegisteredPoStProof_StackedDrgWindow8MiBV1 + case abi.RegisteredPoStProof_StackedDrgWinning512MiBV1: + proofType = abi.RegisteredPoStProof_StackedDrgWindow512MiBV1 + case abi.RegisteredPoStProof_StackedDrgWinning32GiBV1: + proofType = abi.RegisteredPoStProof_StackedDrgWindow32GiBV1 + case abi.RegisteredPoStProof_StackedDrgWinning64GiBV1: + proofType = abi.RegisteredPoStProof_StackedDrgWindow64GiBV1 + default: + return nil, xerrors.Errorf("unknown proof type %d", info.WindowPoStProofType) + } + + ids, err := pv.GenerateWinningPoStSectorChallenge(ctx, proofType, abi.ActorID(mid), rand, numProvSect) if err != nil { return nil, xerrors.Errorf("generating winning post challenges: %w", err) } From 8dc49db30db382a6fd0b0238e6eca1939ff69d40 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 18 Jan 2021 18:08:41 -0800 Subject: [PATCH 20/58] window <-> winning --- chain/stmgr/utils.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index f7ed4c2e3..d7bc42648 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -215,16 +215,16 @@ func GetSectorsForWinningPoSt(ctx context.Context, nv network.Version, pv ffiwra // TODO: move this to somewhere in specs-actors or the state types. var proofType abi.RegisteredPoStProof switch info.WindowPoStProofType { - case abi.RegisteredPoStProof_StackedDrgWinning2KiBV1: - proofType = abi.RegisteredPoStProof_StackedDrgWindow2KiBV1 - case abi.RegisteredPoStProof_StackedDrgWinning8MiBV1: - proofType = abi.RegisteredPoStProof_StackedDrgWindow8MiBV1 - case abi.RegisteredPoStProof_StackedDrgWinning512MiBV1: - proofType = abi.RegisteredPoStProof_StackedDrgWindow512MiBV1 - case abi.RegisteredPoStProof_StackedDrgWinning32GiBV1: - proofType = abi.RegisteredPoStProof_StackedDrgWindow32GiBV1 - case abi.RegisteredPoStProof_StackedDrgWinning64GiBV1: - proofType = abi.RegisteredPoStProof_StackedDrgWindow64GiBV1 + case abi.RegisteredPoStProof_StackedDrgWindow2KiBV1: + proofType = abi.RegisteredPoStProof_StackedDrgWinning2KiBV1 + case abi.RegisteredPoStProof_StackedDrgWindow8MiBV1: + proofType = abi.RegisteredPoStProof_StackedDrgWinning8MiBV1 + case abi.RegisteredPoStProof_StackedDrgWindow512MiBV1: + proofType = abi.RegisteredPoStProof_StackedDrgWinning512MiBV1 + case abi.RegisteredPoStProof_StackedDrgWindow32GiBV1: + proofType = abi.RegisteredPoStProof_StackedDrgWinning32GiBV1 + case abi.RegisteredPoStProof_StackedDrgWindow64GiBV1: + proofType = abi.RegisteredPoStProof_StackedDrgWinning64GiBV1 default: return nil, xerrors.Errorf("unknown proof type %d", info.WindowPoStProofType) } From 9d2c430138a4fd7d3c2e4b1c4d8abaf8eaea39bd Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 18 Jan 2021 16:06:16 -0800 Subject: [PATCH 21/58] remove abstract map constructor/loader Different maps have different parameters now so we just construct/load them manually where needed. --- chain/actors/adt/adt.go | 56 ----------------- chain/actors/builtin/verifreg/util.go | 17 ++--- chain/actors/builtin/verifreg/v0.go | 17 +++-- chain/actors/builtin/verifreg/v2.go | 17 +++-- chain/actors/builtin/verifreg/v3.go | 18 ++++-- chain/state/statetree.go | 90 +++++++++++++++------------ chain/stmgr/stmgr.go | 9 ++- chain/types/state.go | 4 +- 8 files changed, 106 insertions(+), 122 deletions(-) diff --git a/chain/actors/adt/adt.go b/chain/actors/adt/adt.go index 7a3007fa8..084471bb8 100644 --- a/chain/actors/adt/adt.go +++ b/chain/actors/adt/adt.go @@ -2,17 +2,9 @@ package adt import ( "github.com/ipfs/go-cid" - "golang.org/x/xerrors" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/cbor" - "github.com/filecoin-project/go-state-types/network" - - "github.com/filecoin-project/lotus/chain/actors" - - adt0 "github.com/filecoin-project/specs-actors/actors/util/adt" - adt2 "github.com/filecoin-project/specs-actors/v2/actors/util/adt" - adt3 "github.com/filecoin-project/specs-actors/v3/actors/util/adt" ) type Map interface { @@ -25,30 +17,6 @@ type Map interface { ForEach(v cbor.Unmarshaler, fn func(key string) error) error } -func AsMap(store Store, root cid.Cid, version actors.Version, v3bitwidth int) (Map, error) { - switch version { - case actors.Version0: - return adt0.AsMap(store, root) - case actors.Version2: - return adt2.AsMap(store, root) - case actors.Version3: - return adt3.AsMap(store, root, v3bitwidth) - } - return nil, xerrors.Errorf("unknown network version: %d", version) -} - -func NewMap(store Store, version actors.Version, bitwidth int) (Map, error) { - switch version { - case actors.Version0: - return adt0.MakeEmptyMap(store), nil - case actors.Version2: - return adt2.MakeEmptyMap(store), nil - case actors.Version3: - return adt3.MakeEmptyMap(store, bitwidth), nil - } - return nil, xerrors.Errorf("unknown network version: %d", version) -} - type Array interface { Root() (cid.Cid, error) @@ -59,27 +27,3 @@ type Array interface { ForEach(v cbor.Unmarshaler, fn func(idx int64) error) error } - -func AsArray(store Store, root cid.Cid, version network.Version, bitwidth int) (Array, error) { - switch actors.VersionForNetwork(version) { - case actors.Version0: - return adt0.AsArray(store, root) - case actors.Version2: - return adt2.AsArray(store, root) - case actors.Version3: - return adt3.AsArray(store, root, bitwidth) - } - return nil, xerrors.Errorf("unknown network version: %d", version) -} - -func NewArray(store Store, version actors.Version, bitwidth int) (Array, error) { - switch version { - case actors.Version0: - return adt0.MakeEmptyArray(store), nil - case actors.Version2: - return adt2.MakeEmptyArray(store), nil - case actors.Version3: - return adt3.MakeEmptyArray(store, bitwidth) - } - return nil, xerrors.Errorf("unknown network version: %d", version) -} diff --git a/chain/actors/builtin/verifreg/util.go b/chain/actors/builtin/verifreg/util.go index b7768439c..16e50c50a 100644 --- a/chain/actors/builtin/verifreg/util.go +++ b/chain/actors/builtin/verifreg/util.go @@ -6,18 +6,21 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/adt" - builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" - "github.com/ipfs/go-cid" "golang.org/x/xerrors" ) +// taking this as a function instead of asking the caller to call it helps reduce some of the error +// checking boilerplate. +// +// "go made me do it" +type rootFunc func() (adt.Map, error) + // Assumes that the bitwidth for v3 HAMTs is the DefaultHamtBitwidth -func getDataCap(store adt.Store, ver actors.Version, root cid.Cid, addr address.Address) (bool, abi.StoragePower, error) { +func getDataCap(store adt.Store, ver actors.Version, root rootFunc, addr address.Address) (bool, abi.StoragePower, error) { if addr.Protocol() != address.ID { return false, big.Zero(), xerrors.Errorf("can only look up ID addresses") } - - vh, err := adt.AsMap(store, root, ver, builtin3.DefaultHamtBitwidth) + vh, err := root() if err != nil { return false, big.Zero(), xerrors.Errorf("loading verifreg: %w", err) } @@ -33,8 +36,8 @@ func getDataCap(store adt.Store, ver actors.Version, root cid.Cid, addr address. } // Assumes that the bitwidth for v3 HAMTs is the DefaultHamtBitwidth -func forEachCap(store adt.Store, ver actors.Version, root cid.Cid, cb func(addr address.Address, dcap abi.StoragePower) error) error { - vh, err := adt.AsMap(store, root, ver, builtin3.DefaultHamtBitwidth) +func forEachCap(store adt.Store, ver actors.Version, root rootFunc, cb func(addr address.Address, dcap abi.StoragePower) error) error { + vh, err := root() if err != nil { return xerrors.Errorf("loading verified clients: %w", err) } diff --git a/chain/actors/builtin/verifreg/v0.go b/chain/actors/builtin/verifreg/v0.go index 64def4706..0dc4696f4 100644 --- a/chain/actors/builtin/verifreg/v0.go +++ b/chain/actors/builtin/verifreg/v0.go @@ -9,6 +9,7 @@ import ( "github.com/filecoin-project/lotus/chain/actors/adt" verifreg0 "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" + adt0 "github.com/filecoin-project/specs-actors/actors/util/adt" ) var _ State = (*state0)(nil) @@ -32,17 +33,25 @@ func (s *state0) RootKey() (address.Address, error) { } func (s *state0) VerifiedClientDataCap(addr address.Address) (bool, abi.StoragePower, error) { - return getDataCap(s.store, actors.Version0, s.State.VerifiedClients, addr) + return getDataCap(s.store, actors.Version0, s.verifiedClients, addr) } func (s *state0) VerifierDataCap(addr address.Address) (bool, abi.StoragePower, error) { - return getDataCap(s.store, actors.Version0, s.State.Verifiers, addr) + return getDataCap(s.store, actors.Version0, s.verifiers, addr) } func (s *state0) ForEachVerifier(cb func(addr address.Address, dcap abi.StoragePower) error) error { - return forEachCap(s.store, actors.Version0, s.State.Verifiers, cb) + return forEachCap(s.store, actors.Version0, s.verifiers, cb) } func (s *state0) ForEachClient(cb func(addr address.Address, dcap abi.StoragePower) error) error { - return forEachCap(s.store, actors.Version0, s.State.VerifiedClients, cb) + return forEachCap(s.store, actors.Version0, s.verifiedClients, cb) +} + +func (s *state0) verifiedClients() (adt.Map, error) { + return adt0.AsMap(s.store, s.VerifiedClients) +} + +func (s *state0) verifiers() (adt.Map, error) { + return adt0.AsMap(s.store, s.Verifiers) } diff --git a/chain/actors/builtin/verifreg/v2.go b/chain/actors/builtin/verifreg/v2.go index 5ee3bad05..a5ef84532 100644 --- a/chain/actors/builtin/verifreg/v2.go +++ b/chain/actors/builtin/verifreg/v2.go @@ -9,6 +9,7 @@ import ( "github.com/filecoin-project/lotus/chain/actors/adt" verifreg2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/verifreg" + adt2 "github.com/filecoin-project/specs-actors/v2/actors/util/adt" ) var _ State = (*state2)(nil) @@ -32,17 +33,25 @@ func (s *state2) RootKey() (address.Address, error) { } func (s *state2) VerifiedClientDataCap(addr address.Address) (bool, abi.StoragePower, error) { - return getDataCap(s.store, actors.Version2, s.State.VerifiedClients, addr) + return getDataCap(s.store, actors.Version2, s.verifiedClients, addr) } func (s *state2) VerifierDataCap(addr address.Address) (bool, abi.StoragePower, error) { - return getDataCap(s.store, actors.Version2, s.State.Verifiers, addr) + return getDataCap(s.store, actors.Version2, s.verifiers, addr) } func (s *state2) ForEachVerifier(cb func(addr address.Address, dcap abi.StoragePower) error) error { - return forEachCap(s.store, actors.Version2, s.State.Verifiers, cb) + return forEachCap(s.store, actors.Version2, s.verifiers, cb) } func (s *state2) ForEachClient(cb func(addr address.Address, dcap abi.StoragePower) error) error { - return forEachCap(s.store, actors.Version2, s.State.VerifiedClients, cb) + return forEachCap(s.store, actors.Version2, s.verifiedClients, cb) +} + +func (s *state2) verifiedClients() (adt.Map, error) { + return adt2.AsMap(s.store, s.VerifiedClients) +} + +func (s *state2) verifiers() (adt.Map, error) { + return adt2.AsMap(s.store, s.Verifiers) } diff --git a/chain/actors/builtin/verifreg/v3.go b/chain/actors/builtin/verifreg/v3.go index 4667412c5..fb0c46d0c 100644 --- a/chain/actors/builtin/verifreg/v3.go +++ b/chain/actors/builtin/verifreg/v3.go @@ -8,7 +8,9 @@ import ( "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/adt" + builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" verifreg3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/verifreg" + adt3 "github.com/filecoin-project/specs-actors/v3/actors/util/adt" ) var _ State = (*state3)(nil) @@ -32,17 +34,25 @@ func (s *state3) RootKey() (address.Address, error) { } func (s *state3) VerifiedClientDataCap(addr address.Address) (bool, abi.StoragePower, error) { - return getDataCap(s.store, actors.Version3, s.State.VerifiedClients, addr) + return getDataCap(s.store, actors.Version3, s.verifiedClients, addr) } func (s *state3) VerifierDataCap(addr address.Address) (bool, abi.StoragePower, error) { - return getDataCap(s.store, actors.Version3, s.State.Verifiers, addr) + return getDataCap(s.store, actors.Version3, s.verifiers, addr) } func (s *state3) ForEachVerifier(cb func(addr address.Address, dcap abi.StoragePower) error) error { - return forEachCap(s.store, actors.Version3, s.State.Verifiers, cb) + return forEachCap(s.store, actors.Version3, s.verifiers, cb) } func (s *state3) ForEachClient(cb func(addr address.Address, dcap abi.StoragePower) error) error { - return forEachCap(s.store, actors.Version3, s.State.VerifiedClients, cb) + return forEachCap(s.store, actors.Version3, s.verifiedClients, cb) +} + +func (s *state3) verifiedClients() (adt.Map, error) { + return adt3.AsMap(s.store, s.VerifiedClients, builtin3.DefaultHamtBitwidth) +} + +func (s *state3) verifiers() (adt.Map, error) { + return adt3.AsMap(s.store, s.Verifiers, builtin3.DefaultHamtBitwidth) } diff --git a/chain/state/statetree.go b/chain/state/statetree.go index d8cdca73a..d31296040 100644 --- a/chain/state/statetree.go +++ b/chain/state/statetree.go @@ -5,8 +5,6 @@ import ( "context" "fmt" - builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" - "github.com/ipfs/go-cid" cbor "github.com/ipfs/go-ipld-cbor" logging "github.com/ipfs/go-log/v2" @@ -22,6 +20,12 @@ import ( "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/types" + + adt0 "github.com/filecoin-project/specs-actors/actors/util/adt" + adt2 "github.com/filecoin-project/specs-actors/v2/actors/util/adt" + adt3 "github.com/filecoin-project/specs-actors/v3/actors/util/adt" + + builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" ) var log = logging.Logger("statetree") @@ -146,23 +150,12 @@ func VersionForNetwork(ver network.Version) types.StateTreeVersion { return types.StateTreeVersion1 } -func adtForSTVersion(ver types.StateTreeVersion) actors.Version { - switch ver { - case types.StateTreeVersion0: - return actors.Version0 - case types.StateTreeVersion1: - return actors.Version2 - default: - panic("unhandled state tree version") - } -} - func NewStateTree(cst cbor.IpldStore, ver types.StateTreeVersion) (*StateTree, error) { var info cid.Cid switch ver { case types.StateTreeVersion0: // info is undefined - case types.StateTreeVersion1: + case types.StateTreeVersion1, types.StateTreeVersion2: var err error info, err = cst.Put(context.TODO(), new(types.StateInfo0)) if err != nil { @@ -171,14 +164,22 @@ func NewStateTree(cst cbor.IpldStore, ver types.StateTreeVersion) (*StateTree, e default: return nil, xerrors.Errorf("unsupported state tree version: %d", ver) } - // TODO: Confirm this is correct - root, err := adt.NewMap(adt.WrapStore(context.TODO(), cst), adtForSTVersion(ver), builtin3.DefaultHamtBitwidth) - if err != nil { - return nil, err + + var hamt adt.Map + store := adt.WrapStore(context.TODO(), cst) + switch ver { + case types.StateTreeVersion0: + hamt = adt0.MakeEmptyMap(store) + case types.StateTreeVersion1: + hamt = adt2.MakeEmptyMap(store) + case types.StateTreeVersion2: + hamt = adt3.MakeEmptyMap(store, builtin3.DefaultHamtBitwidth) + default: + return nil, xerrors.Errorf("unsupported state tree version: %d", ver) } s := &StateTree{ - root: root, + root: hamt, info: info, version: ver, Store: cst, @@ -197,32 +198,39 @@ func LoadStateTree(cst cbor.IpldStore, c cid.Cid) (*StateTree, error) { root.Version = types.StateTreeVersion0 } - switch root.Version { - case types.StateTreeVersion0, types.StateTreeVersion1: - // Load the actual state-tree HAMT. - nd, err := adt.AsMap( - adt.WrapStore(context.TODO(), cst), root.Actors, - adtForSTVersion(root.Version), - // TODO: Confirm this is correct - builtin3.DefaultHamtBitwidth, - ) - if err != nil { - log.Errorf("loading hamt node %s failed: %s", c, err) - return nil, err - } + store := adt.WrapStore(context.TODO(), cst) - s := &StateTree{ - root: nd, - info: root.Info, - version: root.Version, - Store: cst, - snaps: newStateSnaps(), - } - s.lookupIDFun = s.lookupIDinternal - return s, nil + var ( + hamt adt.Map + err error + ) + + switch root.Version { + case types.StateTreeVersion0: + hamt, err = adt0.AsMap(store, root.Actors) + case types.StateTreeVersion1: + hamt, err = adt2.AsMap(store, root.Actors) + case types.StateTreeVersion2: + hamt, err = adt3.AsMap(store, root.Actors, builtin3.DefaultHamtBitwidth) default: return nil, xerrors.Errorf("unsupported state tree version: %d", root.Version) } + + if err != nil { + log.Errorf("loading hamt node %s failed: %s", c, err) + return nil, err + } + + s := &StateTree{ + root: hamt, + info: root.Info, + version: root.Version, + Store: cst, + snaps: newStateSnaps(), + } + s.lookupIDFun = s.lookupIDinternal + + return s, nil } func (st *StateTree) SetActor(addr address.Address, act *types.Actor) error { diff --git a/chain/stmgr/stmgr.go b/chain/stmgr/stmgr.go index 8a6315deb..84e9e1744 100644 --- a/chain/stmgr/stmgr.go +++ b/chain/stmgr/stmgr.go @@ -21,6 +21,9 @@ import ( // Used for genesis. msig0 "github.com/filecoin-project/specs-actors/actors/builtin/multisig" + // we use the same adt for all receipts + blockadt "github.com/filecoin-project/specs-actors/actors/util/adt" + "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors" @@ -385,11 +388,7 @@ func (sm *StateManager) ApplyBlocks(ctx context.Context, parentEpoch abi.ChainEp return cid.Cid{}, cid.Cid{}, err } - // XXX: Is the height correct? Or should it be epoch-1? - rectarr, err := adt.NewArray(sm.cs.Store(ctx), actors.VersionForNetwork(sm.GetNtwkVersion(ctx, epoch)), ReceiptAmtBitwidth) - if err != nil { - return cid.Undef, cid.Undef, xerrors.Errorf("failed to create receipts amt: %w", err) - } + rectarr := blockadt.MakeEmptyArray(sm.cs.Store(ctx)) for i, receipt := range receipts { if err := rectarr.Set(uint64(i), receipt); err != nil { return cid.Undef, cid.Undef, xerrors.Errorf("failed to build receipts amt: %w", err) diff --git a/chain/types/state.go b/chain/types/state.go index a96883604..f6a3472f8 100644 --- a/chain/types/state.go +++ b/chain/types/state.go @@ -9,8 +9,10 @@ type StateTreeVersion uint64 const ( // StateTreeVersion0 corresponds to actors < v2. StateTreeVersion0 StateTreeVersion = iota - // StateTreeVersion1 corresponds to actors >= v2. + // StateTreeVersion1 corresponds to actors [v2, v3) StateTreeVersion1 + // StateTreeVersion2 corresponds to actors >= v3. + StateTreeVersion2 ) type StateRoot struct { From 1a790f5ee322d855e52c37cec20b951edfcb03cd Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 18 Jan 2021 16:28:18 -0800 Subject: [PATCH 22/58] use actors state-tree abstraction Well, not fully, but this is enough to ensure we use the correct bitwidth and such. --- chain/state/statetree.go | 57 ++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/chain/state/statetree.go b/chain/state/statetree.go index d31296040..d7990b9b8 100644 --- a/chain/state/statetree.go +++ b/chain/state/statetree.go @@ -21,11 +21,9 @@ import ( "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/types" - adt0 "github.com/filecoin-project/specs-actors/actors/util/adt" - adt2 "github.com/filecoin-project/specs-actors/v2/actors/util/adt" - adt3 "github.com/filecoin-project/specs-actors/v3/actors/util/adt" - - builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" + states0 "github.com/filecoin-project/specs-actors/actors/states" + states2 "github.com/filecoin-project/specs-actors/v2/actors/states" + states3 "github.com/filecoin-project/specs-actors/v3/actors/states" ) var log = logging.Logger("statetree") @@ -165,15 +163,27 @@ func NewStateTree(cst cbor.IpldStore, ver types.StateTreeVersion) (*StateTree, e return nil, xerrors.Errorf("unsupported state tree version: %d", ver) } - var hamt adt.Map store := adt.WrapStore(context.TODO(), cst) + var hamt adt.Map switch ver { case types.StateTreeVersion0: - hamt = adt0.MakeEmptyMap(store) + tree, err := states0.NewTree(store) + if err != nil { + return nil, xerrors.Errorf("failed to create state tree: %w", err) + } + hamt = tree.Map case types.StateTreeVersion1: - hamt = adt2.MakeEmptyMap(store) + tree, err := states2.NewTree(store) + if err != nil { + return nil, xerrors.Errorf("failed to create state tree: %w", err) + } + hamt = tree.Map case types.StateTreeVersion2: - hamt = adt3.MakeEmptyMap(store, builtin3.DefaultHamtBitwidth) + tree, err := states3.NewTree(store) + if err != nil { + return nil, xerrors.Errorf("failed to create state tree: %w", err) + } + hamt = tree.Map default: return nil, xerrors.Errorf("unsupported state tree version: %d", ver) } @@ -200,27 +210,30 @@ func LoadStateTree(cst cbor.IpldStore, c cid.Cid) (*StateTree, error) { store := adt.WrapStore(context.TODO(), cst) - var ( - hamt adt.Map - err error - ) - + var hamt adt.Map switch root.Version { case types.StateTreeVersion0: - hamt, err = adt0.AsMap(store, root.Actors) + tree, err := states0.LoadTree(store, root.Actors) + if err != nil { + return nil, xerrors.Errorf("failed to load state tree: %w", err) + } + hamt = tree.Map case types.StateTreeVersion1: - hamt, err = adt2.AsMap(store, root.Actors) + tree, err := states2.LoadTree(store, root.Actors) + if err != nil { + return nil, xerrors.Errorf("failed to load state tree: %w", err) + } + hamt = tree.Map case types.StateTreeVersion2: - hamt, err = adt3.AsMap(store, root.Actors, builtin3.DefaultHamtBitwidth) + tree, err := states3.LoadTree(store, root.Actors) + if err != nil { + return nil, xerrors.Errorf("failed to load state tree: %w", err) + } + hamt = tree.Map default: return nil, xerrors.Errorf("unsupported state tree version: %d", root.Version) } - if err != nil { - log.Errorf("loading hamt node %s failed: %s", c, err) - return nil, err - } - s := &StateTree{ root: hamt, info: root.Info, From 1f62c07789535980e848fd805c8165dafd04a5c7 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 18 Jan 2021 17:10:14 -0800 Subject: [PATCH 23/58] add back logging --- chain/state/statetree.go | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/chain/state/statetree.go b/chain/state/statetree.go index d7990b9b8..46a13ccc6 100644 --- a/chain/state/statetree.go +++ b/chain/state/statetree.go @@ -210,29 +210,36 @@ func LoadStateTree(cst cbor.IpldStore, c cid.Cid) (*StateTree, error) { store := adt.WrapStore(context.TODO(), cst) - var hamt adt.Map + var ( + hamt adt.Map + err error + ) switch root.Version { case types.StateTreeVersion0: - tree, err := states0.LoadTree(store, root.Actors) - if err != nil { - return nil, xerrors.Errorf("failed to load state tree: %w", err) + var tree *states0.Tree + tree, err = states0.LoadTree(store, root.Actors) + if tree != nil { + hamt = tree.Map } - hamt = tree.Map case types.StateTreeVersion1: - tree, err := states2.LoadTree(store, root.Actors) - if err != nil { - return nil, xerrors.Errorf("failed to load state tree: %w", err) + var tree *states2.Tree + tree, err = states2.LoadTree(store, root.Actors) + if tree != nil { + hamt = tree.Map } - hamt = tree.Map case types.StateTreeVersion2: - tree, err := states3.LoadTree(store, root.Actors) - if err != nil { - return nil, xerrors.Errorf("failed to load state tree: %w", err) + var tree *states3.Tree + tree, err = states3.LoadTree(store, root.Actors) + if tree != nil { + hamt = tree.Map } - hamt = tree.Map default: return nil, xerrors.Errorf("unsupported state tree version: %d", root.Version) } + if err != nil { + log.Errorf("failed to load state tree: %s", err) + return nil, xerrors.Errorf("failed to load state tree: %w", err) + } s := &StateTree{ root: hamt, From 126a5c1cf854c3816aeaf86a297f9a736cdae0fc Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 18 Jan 2021 17:11:02 -0800 Subject: [PATCH 24/58] chore: fix nolint comment --- cmd/lotus-shed/datastore.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/lotus-shed/datastore.go b/cmd/lotus-shed/datastore.go index 8cdc1630c..e0c4465b5 100644 --- a/cmd/lotus-shed/datastore.go +++ b/cmd/lotus-shed/datastore.go @@ -120,7 +120,7 @@ var datastoreGetCmd = &cli.Command{ }, ArgsUsage: "[namespace key]", Action: func(cctx *cli.Context) error { - logging.SetLogLevel("badger", "ERROR") // nolint:errchec + logging.SetLogLevel("badger", "ERROR") // nolint:errcheck r, err := repo.NewFS(cctx.String("repo")) if err != nil { From 99ea5b62eac67118306d9af1da6828e5fb07fd5a Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 18 Jan 2021 19:42:23 -0800 Subject: [PATCH 25/58] wire up v3 migration --- build/params_2k.go | 3 ++ build/params_calibnet.go | 3 ++ build/params_mainnet.go | 3 ++ build/params_testground.go | 5 +- chain/stmgr/forks.go | 97 ++++++++++++++++++++++++++++---------- 5 files changed, 84 insertions(+), 27 deletions(-) diff --git a/build/params_2k.go b/build/params_2k.go index ecac86983..bdf5898fd 100644 --- a/build/params_2k.go +++ b/build/params_2k.go @@ -27,6 +27,9 @@ const UpgradePersianHeight = 25 const UpgradeOrangeHeight = 27 const UpgradeClausHeight = 30 +// TODO +const UpgradeActorsV3Height = -5 + var DrandSchedule = map[abi.ChainEpoch]DrandEnum{ 0: DrandMainnet, } diff --git a/build/params_calibnet.go b/build/params_calibnet.go index 670efa776..a102823db 100644 --- a/build/params_calibnet.go +++ b/build/params_calibnet.go @@ -44,6 +44,9 @@ const UpgradeClausHeight = 161386 // 2021-01-17T19:00:00Z const UpgradeOrangeHeight = 250666 +// TODO +var UpgradeActorsV3Height = 99999999 + func init() { policy.SetConsensusMinerMinPower(abi.NewStoragePower(10 << 30)) policy.SetSupportedProofTypes( diff --git a/build/params_mainnet.go b/build/params_mainnet.go index a4c3ab04f..bf322a744 100644 --- a/build/params_mainnet.go +++ b/build/params_mainnet.go @@ -50,6 +50,9 @@ const UpgradeOrangeHeight = 336458 // 2020-12-22T02:00:00Z const UpgradeClausHeight = 343200 +// TODO +const UpgradeActorsV3Height = 999999999 + func init() { policy.SetConsensusMinerMinPower(abi.NewStoragePower(10 << 40)) diff --git a/build/params_testground.go b/build/params_testground.go index 8537ba33f..759b29692 100644 --- a/build/params_testground.go +++ b/build/params_testground.go @@ -90,8 +90,9 @@ var ( UpgradeKumquatHeight abi.ChainEpoch = -6 UpgradeCalicoHeight abi.ChainEpoch = -7 UpgradePersianHeight abi.ChainEpoch = -8 - UpgradeClausHeight abi.ChainEpoch = -9 - UpgradeOrangeHeight abi.ChainEpoch = -10 + UpgradeOrangeHeight abi.ChainEpoch = -9 + UpgradeClausHeight abi.ChainEpoch = -10 + UpgradeActorsV3Height abi.ChainEpoch = -11 DrandSchedule = map[abi.ChainEpoch]DrandEnum{ 0: DrandMainnet, diff --git a/chain/stmgr/forks.go b/chain/stmgr/forks.go index 7fe12d2a8..86308cf19 100644 --- a/chain/stmgr/forks.go +++ b/chain/stmgr/forks.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "encoding/binary" - "math" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" @@ -29,6 +28,7 @@ import ( adt0 "github.com/filecoin-project/specs-actors/actors/util/adt" "github.com/filecoin-project/specs-actors/v2/actors/migration/nv4" "github.com/filecoin-project/specs-actors/v2/actors/migration/nv7" + "github.com/filecoin-project/specs-actors/v3/actors/migration/nv9" "github.com/ipfs/go-cid" cbor "github.com/ipfs/go-ipld-cbor" "golang.org/x/xerrors" @@ -100,32 +100,12 @@ func DefaultUpgradeSchedule() UpgradeSchedule { Height: build.UpgradeOrangeHeight, Network: network.Version9, Migration: nil, + }, { + Height: build.UpgradeActorsV3Height, + Network: network.Version10, + Migration: UpgradeActorsV3, }} - if build.UpgradeActorsV2Height == math.MaxInt64 { // disable actors upgrade - updates = []Upgrade{{ - Height: build.UpgradeBreezeHeight, - Network: network.Version1, - Migration: UpgradeFaucetBurnRecovery, - }, { - Height: build.UpgradeSmokeHeight, - Network: network.Version2, - Migration: nil, - }, { - Height: build.UpgradeIgnitionHeight, - Network: network.Version3, - Migration: UpgradeIgnition, - }, { - Height: build.UpgradeRefuelHeight, - Network: network.Version3, - Migration: UpgradeRefuel, - }, { - Height: build.UpgradeLiftoffHeight, - Network: network.Version3, - Migration: UpgradeLiftoff, - }} - } - for _, u := range updates { if u.Height < 0 { // upgrade disabled @@ -704,6 +684,73 @@ func UpgradeCalico(ctx context.Context, sm *StateManager, cb ExecCallback, root return newRoot, nil } +func UpgradeActorsV3(ctx context.Context, sm *StateManager, cb ExecCallback, root cid.Cid, epoch abi.ChainEpoch, ts *types.TipSet) (cid.Cid, error) { + buf := bufbstore.NewTieredBstore(sm.cs.Blockstore(), bstore.NewTemporarySync()) + store := store.ActorStore(ctx, buf) + + // Load the state root. + + var stateRoot types.StateRoot + if err := store.Get(ctx, root, &stateRoot); err != nil { + return cid.Undef, xerrors.Errorf("failed to decode state root: %w", err) + } + + if stateRoot.Version != types.StateTreeVersion1 { + return cid.Undef, xerrors.Errorf( + "expected state root version 1 for actors v3 upgrade, got %d", + stateRoot.Version, + ) + } + + // Perform the migration + + // TODO: store this somewhere and pre-migrate + cache := nv9.NewMemMigrationCache() + // TODO: tune this. + config := nv9.Config{MaxWorkers: 1} + newHamtRoot, err := nv9.MigrateStateTree(ctx, store, stateRoot.Actors, epoch, config, migrationLogger{}, cache) + if err != nil { + return cid.Undef, xerrors.Errorf("upgrading to actors v2: %w", err) + } + + // Persist the result. + + newRoot, err := store.Put(ctx, &types.StateRoot{ + Version: types.StateTreeVersion2, + Actors: newHamtRoot, + Info: stateRoot.Info, + }) + if err != nil { + return cid.Undef, xerrors.Errorf("failed to persist new state root: %w", err) + } + + // Check the result. + + // perform some basic sanity checks to make sure everything still works. + if newSm, err := state.LoadStateTree(store, newRoot); err != nil { + return cid.Undef, xerrors.Errorf("state tree sanity load failed: %w", err) + } else if newRoot2, err := newSm.Flush(ctx); err != nil { + return cid.Undef, xerrors.Errorf("state tree sanity flush failed: %w", err) + } else if newRoot2 != newRoot { + return cid.Undef, xerrors.Errorf("state-root mismatch: %s != %s", newRoot, newRoot2) + } else if _, err := newSm.GetActor(init_.Address); err != nil { + return cid.Undef, xerrors.Errorf("failed to load init actor after upgrade: %w", err) + } + + // Persist the new tree. + + { + from := buf + to := buf.Read() + + if err := vm.Copy(ctx, from, to, newRoot); err != nil { + return cid.Undef, xerrors.Errorf("copying migrated tree: %w", err) + } + } + + return newRoot, nil +} + func setNetworkName(ctx context.Context, store adt.Store, tree *state.StateTree, name string) error { ia, err := tree.GetActor(builtin0.InitActorAddr) if err != nil { From f6a0da3751506fc6bafd5b6be6c85c2ba0c4cd4e Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Tue, 19 Jan 2021 02:34:08 -0500 Subject: [PATCH 26/58] Add the migrationLogger struct --- chain/stmgr/forks.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/chain/stmgr/forks.go b/chain/stmgr/forks.go index 86308cf19..d1b381c36 100644 --- a/chain/stmgr/forks.go +++ b/chain/stmgr/forks.go @@ -5,6 +5,8 @@ import ( "context" "encoding/binary" + "github.com/filecoin-project/go-state-types/rt" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" @@ -52,6 +54,21 @@ type Upgrade struct { type UpgradeSchedule []Upgrade +type migrationLogger struct{} + +func (ml migrationLogger) Log(level rt.LogLevel, msg string, args ...interface{}) { + switch level { + case rt.DEBUG: + log.Debugf(msg, args...) + case rt.INFO: + log.Infof(msg, args...) + case rt.WARN: + log.Warnf(msg, args...) + case rt.ERROR: + log.Errorf(msg, args...) + } +} + func DefaultUpgradeSchedule() UpgradeSchedule { var us UpgradeSchedule From c8bfbd4f289f51d3c19bdb6448330abf5b6a7cc2 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Tue, 19 Jan 2021 02:34:28 -0500 Subject: [PATCH 27/58] Apply actors v3 upgrade in devnets --- build/params_2k.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/build/params_2k.go b/build/params_2k.go index bdf5898fd..63f7e70b4 100644 --- a/build/params_2k.go +++ b/build/params_2k.go @@ -27,8 +27,7 @@ const UpgradePersianHeight = 25 const UpgradeOrangeHeight = 27 const UpgradeClausHeight = 30 -// TODO -const UpgradeActorsV3Height = -5 +const UpgradeActorsV3Height = 35 var DrandSchedule = map[abi.ChainEpoch]DrandEnum{ 0: DrandMainnet, From 95f68d01610f11022635de0ab73d6311835f9f6c Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Tue, 19 Jan 2021 02:34:55 -0500 Subject: [PATCH 28/58] Register the v3 actor CIDs in the actor registry --- chain/vm/invoker.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/chain/vm/invoker.go b/chain/vm/invoker.go index a5610736a..1c1d04f19 100644 --- a/chain/vm/invoker.go +++ b/chain/vm/invoker.go @@ -17,6 +17,7 @@ import ( exported0 "github.com/filecoin-project/specs-actors/actors/builtin/exported" exported2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/exported" vmr "github.com/filecoin-project/specs-actors/v2/actors/runtime" + exported3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/exported" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/exitcode" @@ -62,6 +63,7 @@ func NewActorRegistry() *ActorRegistry { // add builtInCode using: register(cid, singleton) inv.Register(ActorsVersionPredicate(actors.Version0), exported0.BuiltinActors()...) inv.Register(ActorsVersionPredicate(actors.Version2), exported2.BuiltinActors()...) + inv.Register(ActorsVersionPredicate(actors.Version3), exported3.BuiltinActors()...) return inv } From aa9eef48f0c523a0dd892e85f2bd0a91972e6499 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Tue, 19 Jan 2021 02:35:37 -0500 Subject: [PATCH 29/58] Use temp commit of actors --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 62199668d..0fbd81a84 100644 --- a/go.mod +++ b/go.mod @@ -44,7 +44,7 @@ require ( github.com/filecoin-project/go-storedcounter v0.0.0-20200421200003-1c99c62e8a5b github.com/filecoin-project/specs-actors v0.9.13 github.com/filecoin-project/specs-actors/v2 v2.3.4 - github.com/filecoin-project/specs-actors/v3 v3.0.0-20210115014158-be9804e44879 + github.com/filecoin-project/specs-actors/v3 v3.0.0-20210119072803-deaad8e767fc github.com/filecoin-project/specs-storage v0.1.1-0.20201105051918-5188d9774506 github.com/filecoin-project/test-vectors/schema v0.0.5 github.com/gbrlsnchs/jwt/v3 v3.0.0-beta.1 diff --git a/go.sum b/go.sum index f53d98300..1fddc824e 100644 --- a/go.sum +++ b/go.sum @@ -307,8 +307,8 @@ github.com/filecoin-project/specs-actors/v2 v2.3.2 h1:2Vcf4CGa29kRh4JJ02m+FbvD/p github.com/filecoin-project/specs-actors/v2 v2.3.2/go.mod h1:UuJQLoTx/HPvvWeqlIFmC/ywlOLHNe8SNQ3OunFbu2Y= github.com/filecoin-project/specs-actors/v2 v2.3.4 h1:NZK2oMCcA71wNsUzDBmLQyRMzcCnX9tDGvwZ53G67j8= github.com/filecoin-project/specs-actors/v2 v2.3.4/go.mod h1:UuJQLoTx/HPvvWeqlIFmC/ywlOLHNe8SNQ3OunFbu2Y= -github.com/filecoin-project/specs-actors/v3 v3.0.0-20210115014158-be9804e44879 h1:rX+rISGIh3/VQf/rXPAQ0waJ2JDXCO/o68pmIP+zQHk= -github.com/filecoin-project/specs-actors/v3 v3.0.0-20210115014158-be9804e44879/go.mod h1:kJ/Jk5TYkSC7eJR4RPl2VYgYJOsLPeERAmGkeFMXiLM= +github.com/filecoin-project/specs-actors/v3 v3.0.0-20210119072803-deaad8e767fc h1:0a494XkFAp3dFwfNVCVDFa6rRNCSWVzxuYWq+5xhxo0= +github.com/filecoin-project/specs-actors/v3 v3.0.0-20210119072803-deaad8e767fc/go.mod h1:kJ/Jk5TYkSC7eJR4RPl2VYgYJOsLPeERAmGkeFMXiLM= github.com/filecoin-project/specs-storage v0.1.1-0.20201105051918-5188d9774506 h1:Ur/l2+6qN+lQiqjozWWc5p9UDaAMDZKTlDS98oRnlIw= github.com/filecoin-project/specs-storage v0.1.1-0.20201105051918-5188d9774506/go.mod h1:nJRRM7Aa9XVvygr3W9k6xGF46RWzr2zxF/iGoAIfA/g= github.com/filecoin-project/test-vectors/schema v0.0.5 h1:w3zHQhzM4pYxJDl21avXjOKBLF8egrvwUwjpT8TquDg= From 64e805926fe05a8dd4b84b9c7a32592dae94aa65 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 19 Jan 2021 08:48:10 -0800 Subject: [PATCH 30/58] update specs-actors for migration name change Actors v3 is network version 10. --- chain/stmgr/forks.go | 8 ++++---- go.mod | 4 ++-- go.sum | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/chain/stmgr/forks.go b/chain/stmgr/forks.go index d1b381c36..c87b384ba 100644 --- a/chain/stmgr/forks.go +++ b/chain/stmgr/forks.go @@ -30,7 +30,7 @@ import ( adt0 "github.com/filecoin-project/specs-actors/actors/util/adt" "github.com/filecoin-project/specs-actors/v2/actors/migration/nv4" "github.com/filecoin-project/specs-actors/v2/actors/migration/nv7" - "github.com/filecoin-project/specs-actors/v3/actors/migration/nv9" + "github.com/filecoin-project/specs-actors/v3/actors/migration/nv10" "github.com/ipfs/go-cid" cbor "github.com/ipfs/go-ipld-cbor" "golang.org/x/xerrors" @@ -722,10 +722,10 @@ func UpgradeActorsV3(ctx context.Context, sm *StateManager, cb ExecCallback, roo // Perform the migration // TODO: store this somewhere and pre-migrate - cache := nv9.NewMemMigrationCache() + cache := nv10.NewMemMigrationCache() // TODO: tune this. - config := nv9.Config{MaxWorkers: 1} - newHamtRoot, err := nv9.MigrateStateTree(ctx, store, stateRoot.Actors, epoch, config, migrationLogger{}, cache) + config := nv10.Config{MaxWorkers: 1} + newHamtRoot, err := nv10.MigrateStateTree(ctx, store, stateRoot.Actors, epoch, config, migrationLogger{}, cache) if err != nil { return cid.Undef, xerrors.Errorf("upgrading to actors v2: %w", err) } diff --git a/go.mod b/go.mod index 0fbd81a84..de7ba02d9 100644 --- a/go.mod +++ b/go.mod @@ -38,13 +38,13 @@ require ( github.com/filecoin-project/go-multistore v0.0.3 github.com/filecoin-project/go-padreader v0.0.0-20200903213702-ed5fae088b20 github.com/filecoin-project/go-paramfetch v0.0.2-0.20200701152213-3e0f0afdc261 - github.com/filecoin-project/go-state-types v0.0.0-20201203022337-7cab7f0d4bfb + github.com/filecoin-project/go-state-types v0.0.0-20210119062722-4adba5aaea71 github.com/filecoin-project/go-statemachine v0.0.0-20200925024713-05bd7c71fbfe github.com/filecoin-project/go-statestore v0.1.0 github.com/filecoin-project/go-storedcounter v0.0.0-20200421200003-1c99c62e8a5b github.com/filecoin-project/specs-actors v0.9.13 github.com/filecoin-project/specs-actors/v2 v2.3.4 - github.com/filecoin-project/specs-actors/v3 v3.0.0-20210119072803-deaad8e767fc + github.com/filecoin-project/specs-actors/v3 v3.0.0-20210119164417-c1011929b92a github.com/filecoin-project/specs-storage v0.1.1-0.20201105051918-5188d9774506 github.com/filecoin-project/test-vectors/schema v0.0.5 github.com/gbrlsnchs/jwt/v3 v3.0.0-beta.1 diff --git a/go.sum b/go.sum index 1fddc824e..778d930e2 100644 --- a/go.sum +++ b/go.sum @@ -290,8 +290,8 @@ github.com/filecoin-project/go-state-types v0.0.0-20200904021452-1883f36ca2f4/go github.com/filecoin-project/go-state-types v0.0.0-20200928172055-2df22083d8ab/go.mod h1:ezYnPf0bNkTsDibL/psSz5dy4B5awOJ/E7P2Saeep8g= github.com/filecoin-project/go-state-types v0.0.0-20201102161440-c8033295a1fc h1:+hbMY4Pcx2oizrfH08VWXwrj5mU8aJT6g0UNxGHFCGU= github.com/filecoin-project/go-state-types v0.0.0-20201102161440-c8033295a1fc/go.mod h1:ezYnPf0bNkTsDibL/psSz5dy4B5awOJ/E7P2Saeep8g= -github.com/filecoin-project/go-state-types v0.0.0-20201203022337-7cab7f0d4bfb h1:f7Y9QeUfT+hX+OOjtZ3j1e2KlGWg7ozI7W444Qa+ZJ0= -github.com/filecoin-project/go-state-types v0.0.0-20201203022337-7cab7f0d4bfb/go.mod h1:ezYnPf0bNkTsDibL/psSz5dy4B5awOJ/E7P2Saeep8g= +github.com/filecoin-project/go-state-types v0.0.0-20210119062722-4adba5aaea71 h1:Cas/CUB4ybYpdxvW7LouaydE16cpwdq3vvS3qgZuU+Q= +github.com/filecoin-project/go-state-types v0.0.0-20210119062722-4adba5aaea71/go.mod h1:ezYnPf0bNkTsDibL/psSz5dy4B5awOJ/E7P2Saeep8g= github.com/filecoin-project/go-statemachine v0.0.0-20200925024713-05bd7c71fbfe h1:dF8u+LEWeIcTcfUcCf3WFVlc81Fr2JKg8zPzIbBDKDw= github.com/filecoin-project/go-statemachine v0.0.0-20200925024713-05bd7c71fbfe/go.mod h1:FGwQgZAt2Gh5mjlwJUlVB62JeYdo+if0xWxSEfBD9ig= github.com/filecoin-project/go-statestore v0.1.0 h1:t56reH59843TwXHkMcwyuayStBIiWBRilQjQ+5IiwdQ= @@ -307,8 +307,8 @@ github.com/filecoin-project/specs-actors/v2 v2.3.2 h1:2Vcf4CGa29kRh4JJ02m+FbvD/p github.com/filecoin-project/specs-actors/v2 v2.3.2/go.mod h1:UuJQLoTx/HPvvWeqlIFmC/ywlOLHNe8SNQ3OunFbu2Y= github.com/filecoin-project/specs-actors/v2 v2.3.4 h1:NZK2oMCcA71wNsUzDBmLQyRMzcCnX9tDGvwZ53G67j8= github.com/filecoin-project/specs-actors/v2 v2.3.4/go.mod h1:UuJQLoTx/HPvvWeqlIFmC/ywlOLHNe8SNQ3OunFbu2Y= -github.com/filecoin-project/specs-actors/v3 v3.0.0-20210119072803-deaad8e767fc h1:0a494XkFAp3dFwfNVCVDFa6rRNCSWVzxuYWq+5xhxo0= -github.com/filecoin-project/specs-actors/v3 v3.0.0-20210119072803-deaad8e767fc/go.mod h1:kJ/Jk5TYkSC7eJR4RPl2VYgYJOsLPeERAmGkeFMXiLM= +github.com/filecoin-project/specs-actors/v3 v3.0.0-20210119164417-c1011929b92a h1:btGMXLApysCrsW4xAmGeBolXbeblSGrPXmQuediZR/0= +github.com/filecoin-project/specs-actors/v3 v3.0.0-20210119164417-c1011929b92a/go.mod h1:wJvqbogPtJVRJC3dMWHvknf7RWkXPWPS7HzfMYJoEXM= github.com/filecoin-project/specs-storage v0.1.1-0.20201105051918-5188d9774506 h1:Ur/l2+6qN+lQiqjozWWc5p9UDaAMDZKTlDS98oRnlIw= github.com/filecoin-project/specs-storage v0.1.1-0.20201105051918-5188d9774506/go.mod h1:nJRRM7Aa9XVvygr3W9k6xGF46RWzr2zxF/iGoAIfA/g= github.com/filecoin-project/test-vectors/schema v0.0.5 h1:w3zHQhzM4pYxJDl21avXjOKBLF8egrvwUwjpT8TquDg= From dffa514518bd3300f7d5b5bd12e8547cd555e20f Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 19 Jan 2021 14:53:16 -0800 Subject: [PATCH 31/58] update specs-actors for h/amt interface refactor --- go.mod | 2 +- go.sum | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index de7ba02d9..b243ecab4 100644 --- a/go.mod +++ b/go.mod @@ -44,7 +44,7 @@ require ( github.com/filecoin-project/go-storedcounter v0.0.0-20200421200003-1c99c62e8a5b github.com/filecoin-project/specs-actors v0.9.13 github.com/filecoin-project/specs-actors/v2 v2.3.4 - github.com/filecoin-project/specs-actors/v3 v3.0.0-20210119164417-c1011929b92a + github.com/filecoin-project/specs-actors/v3 v3.0.0-20210119222031-845089a6d258 github.com/filecoin-project/specs-storage v0.1.1-0.20201105051918-5188d9774506 github.com/filecoin-project/test-vectors/schema v0.0.5 github.com/gbrlsnchs/jwt/v3 v3.0.0-beta.1 diff --git a/go.sum b/go.sum index 778d930e2..97bb86e1e 100644 --- a/go.sum +++ b/go.sum @@ -246,8 +246,8 @@ github.com/filecoin-project/go-amt-ipld/v2 v2.1.0 h1:t6qDiuGYYngDqaLc2ZUvdtAg4UN github.com/filecoin-project/go-amt-ipld/v2 v2.1.0/go.mod h1:nfFPoGyX0CU9SkXX8EoCcSuHN1XcbN0c6KBh7yvP5fs= github.com/filecoin-project/go-amt-ipld/v2 v2.1.1-0.20201006184820-924ee87a1349 h1:pIuR0dnMD0i+as8wNnjjHyQrnhP5O5bmba/lmgQeRgU= github.com/filecoin-project/go-amt-ipld/v2 v2.1.1-0.20201006184820-924ee87a1349/go.mod h1:vgmwKBkx+ca5OIeEvstiQgzAZnb7R6QaqE1oEDSqa6g= -github.com/filecoin-project/go-amt-ipld/v3 v3.0.0-20201124192204-2b387ce1bab7 h1:HHKfkAfweGbpnJV60OuG6M0ZAXKrELklLvyjcKI/nKI= -github.com/filecoin-project/go-amt-ipld/v3 v3.0.0-20201124192204-2b387ce1bab7/go.mod h1:Qa95YNAbtoVCTSVtX38aAC1ptBnJfPma1R/zZsKmx4o= +github.com/filecoin-project/go-amt-ipld/v3 v3.0.0 h1:Ou/q82QeHGOhpkedvaxxzpBYuqTxLCcj5OChkDNx4qc= +github.com/filecoin-project/go-amt-ipld/v3 v3.0.0/go.mod h1:Qa95YNAbtoVCTSVtX38aAC1ptBnJfPma1R/zZsKmx4o= github.com/filecoin-project/go-bitfield v0.2.0 h1:gCtLcjskIPtdg4NfN7gQZSQF9yrBQ7mkT0qCJxzGI2Q= github.com/filecoin-project/go-bitfield v0.2.0/go.mod h1:CNl9WG8hgR5mttCnUErjcQjGvuiZjRqK9rHVBsQF4oM= github.com/filecoin-project/go-bitfield v0.2.3-0.20201110211213-fe2c1862e816 h1:RMdzMqe3mu2Z/3N3b9UEfkbGZxukstmZgNC024ybWhA= @@ -275,8 +275,8 @@ github.com/filecoin-project/go-hamt-ipld v0.1.5 h1:uoXrKbCQZ49OHpsTCkrThPNelC4W3 github.com/filecoin-project/go-hamt-ipld v0.1.5/go.mod h1:6Is+ONR5Cd5R6XZoCse1CWaXZc0Hdb/JeX+EQCQzX24= github.com/filecoin-project/go-hamt-ipld/v2 v2.0.0 h1:b3UDemBYN2HNfk3KOXNuxgTTxlWi3xVvbQP0IT38fvM= github.com/filecoin-project/go-hamt-ipld/v2 v2.0.0/go.mod h1:7aWZdaQ1b16BVoQUYR+eEvrDCGJoPLxFpDynFjYfBjI= -github.com/filecoin-project/go-hamt-ipld/v3 v3.0.0-20201203140949-5cdbb5191437 h1:nu2XYXvzy6BNASKVpfCkmUFr6YDf43LMjkMMab+3Z1E= -github.com/filecoin-project/go-hamt-ipld/v3 v3.0.0-20201203140949-5cdbb5191437/go.mod h1:HBuSIxbIKqWjV0/bcJ/e14iIMr1FckG6cyzAsdfttyU= +github.com/filecoin-project/go-hamt-ipld/v3 v3.0.0 h1:aEOgJxSMbJ7XtuX3WxXvbpkBDp4Sqn3jyx/umGyL8s4= +github.com/filecoin-project/go-hamt-ipld/v3 v3.0.0/go.mod h1:gXpNmr3oQx8l3o7qkGyDjJjYSRX7hp/FGOStdqrWyDI= github.com/filecoin-project/go-jsonrpc v0.1.2 h1:MTebUawBHLxxY9gDi1WXuGc89TWIDmsgoDqeZSk9KRw= github.com/filecoin-project/go-jsonrpc v0.1.2/go.mod h1:XBBpuKIMaXIIzeqzO1iucq4GvbF8CxmXRFoezRh+Cx4= github.com/filecoin-project/go-multistore v0.0.3 h1:vaRBY4YiA2UZFPK57RNuewypB8u0DzzQwqsL0XarpnI= @@ -307,8 +307,8 @@ github.com/filecoin-project/specs-actors/v2 v2.3.2 h1:2Vcf4CGa29kRh4JJ02m+FbvD/p github.com/filecoin-project/specs-actors/v2 v2.3.2/go.mod h1:UuJQLoTx/HPvvWeqlIFmC/ywlOLHNe8SNQ3OunFbu2Y= github.com/filecoin-project/specs-actors/v2 v2.3.4 h1:NZK2oMCcA71wNsUzDBmLQyRMzcCnX9tDGvwZ53G67j8= github.com/filecoin-project/specs-actors/v2 v2.3.4/go.mod h1:UuJQLoTx/HPvvWeqlIFmC/ywlOLHNe8SNQ3OunFbu2Y= -github.com/filecoin-project/specs-actors/v3 v3.0.0-20210119164417-c1011929b92a h1:btGMXLApysCrsW4xAmGeBolXbeblSGrPXmQuediZR/0= -github.com/filecoin-project/specs-actors/v3 v3.0.0-20210119164417-c1011929b92a/go.mod h1:wJvqbogPtJVRJC3dMWHvknf7RWkXPWPS7HzfMYJoEXM= +github.com/filecoin-project/specs-actors/v3 v3.0.0-20210119222031-845089a6d258 h1:Lf0T22MAL2p9TBzrI9fd9L5BrCzl1Ve1p9qoKQZbvxM= +github.com/filecoin-project/specs-actors/v3 v3.0.0-20210119222031-845089a6d258/go.mod h1:aVf248CfjfyCmVel4UuFAA3u+9UQjqtqHpgfYv+M+9U= github.com/filecoin-project/specs-storage v0.1.1-0.20201105051918-5188d9774506 h1:Ur/l2+6qN+lQiqjozWWc5p9UDaAMDZKTlDS98oRnlIw= github.com/filecoin-project/specs-storage v0.1.1-0.20201105051918-5188d9774506/go.mod h1:nJRRM7Aa9XVvygr3W9k6xGF46RWzr2zxF/iGoAIfA/g= github.com/filecoin-project/test-vectors/schema v0.0.5 h1:w3zHQhzM4pYxJDl21avXjOKBLF8egrvwUwjpT8TquDg= From 82eee15955b07c3af0edeb583ddb6f6b6b7ad325 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 19 Jan 2021 14:54:06 -0800 Subject: [PATCH 32/58] fix state tree version comment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Łukasz Magiera --- chain/types/state.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chain/types/state.go b/chain/types/state.go index f6a3472f8..c14836ee7 100644 --- a/chain/types/state.go +++ b/chain/types/state.go @@ -9,7 +9,7 @@ type StateTreeVersion uint64 const ( // StateTreeVersion0 corresponds to actors < v2. StateTreeVersion0 StateTreeVersion = iota - // StateTreeVersion1 corresponds to actors [v2, v3) + // StateTreeVersion1 corresponds to actors v2 StateTreeVersion1 // StateTreeVersion2 corresponds to actors >= v3. StateTreeVersion2 From fb5f3c570368a2193602fb7b4cc269bcfb6b7e66 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 19 Jan 2021 16:57:57 -0800 Subject: [PATCH 33/58] update specs actors --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index b243ecab4..164977133 100644 --- a/go.mod +++ b/go.mod @@ -44,7 +44,7 @@ require ( github.com/filecoin-project/go-storedcounter v0.0.0-20200421200003-1c99c62e8a5b github.com/filecoin-project/specs-actors v0.9.13 github.com/filecoin-project/specs-actors/v2 v2.3.4 - github.com/filecoin-project/specs-actors/v3 v3.0.0-20210119222031-845089a6d258 + github.com/filecoin-project/specs-actors/v3 v3.0.0 github.com/filecoin-project/specs-storage v0.1.1-0.20201105051918-5188d9774506 github.com/filecoin-project/test-vectors/schema v0.0.5 github.com/gbrlsnchs/jwt/v3 v3.0.0-beta.1 diff --git a/go.sum b/go.sum index 97bb86e1e..18eb13fe0 100644 --- a/go.sum +++ b/go.sum @@ -307,8 +307,8 @@ github.com/filecoin-project/specs-actors/v2 v2.3.2 h1:2Vcf4CGa29kRh4JJ02m+FbvD/p github.com/filecoin-project/specs-actors/v2 v2.3.2/go.mod h1:UuJQLoTx/HPvvWeqlIFmC/ywlOLHNe8SNQ3OunFbu2Y= github.com/filecoin-project/specs-actors/v2 v2.3.4 h1:NZK2oMCcA71wNsUzDBmLQyRMzcCnX9tDGvwZ53G67j8= github.com/filecoin-project/specs-actors/v2 v2.3.4/go.mod h1:UuJQLoTx/HPvvWeqlIFmC/ywlOLHNe8SNQ3OunFbu2Y= -github.com/filecoin-project/specs-actors/v3 v3.0.0-20210119222031-845089a6d258 h1:Lf0T22MAL2p9TBzrI9fd9L5BrCzl1Ve1p9qoKQZbvxM= -github.com/filecoin-project/specs-actors/v3 v3.0.0-20210119222031-845089a6d258/go.mod h1:aVf248CfjfyCmVel4UuFAA3u+9UQjqtqHpgfYv+M+9U= +github.com/filecoin-project/specs-actors/v3 v3.0.0 h1:hX5LrLSmZsSAV+VoDYucEpiy8Iv3arF+9Lc4Ig7VlXM= +github.com/filecoin-project/specs-actors/v3 v3.0.0/go.mod h1:aVf248CfjfyCmVel4UuFAA3u+9UQjqtqHpgfYv+M+9U= github.com/filecoin-project/specs-storage v0.1.1-0.20201105051918-5188d9774506 h1:Ur/l2+6qN+lQiqjozWWc5p9UDaAMDZKTlDS98oRnlIw= github.com/filecoin-project/specs-storage v0.1.1-0.20201105051918-5188d9774506/go.mod h1:nJRRM7Aa9XVvygr3W9k6xGF46RWzr2zxF/iGoAIfA/g= github.com/filecoin-project/test-vectors/schema v0.0.5 h1:w3zHQhzM4pYxJDl21avXjOKBLF8egrvwUwjpT8TquDg= From 03cd3760bbb561922ec59a2583bda6ec16ee65c4 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 19 Jan 2021 18:06:00 -0800 Subject: [PATCH 34/58] correctly pick the seal type based on the network version Of course, we should really just run all of our tests post actors v2. --- chain/actors/builtin/miner/miner.go | 23 +++++++++++++++++++++-- extern/storage-sealing/sealing.go | 7 ++++++- markets/storageadapter/provider.go | 19 ++++++++++++------- node/impl/client/client.go | 7 ++++++- node/modules/storageminer.go | 15 +++++++++------ 5 files changed, 54 insertions(+), 17 deletions(-) diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index 279ca5e50..3364f6195 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -2,6 +2,7 @@ package miner import ( "github.com/filecoin-project/go-state-types/big" + "github.com/filecoin-project/go-state-types/network" "github.com/ipfs/go-cid" "github.com/libp2p/go-libp2p-core/peer" cbg "github.com/whyrusleeping/cbor-gen" @@ -149,8 +150,26 @@ type DeclareFaultsRecoveredParams = miner0.DeclareFaultsRecoveredParams type SubmitWindowedPoStParams = miner0.SubmitWindowedPoStParams type ProveCommitSectorParams = miner0.ProveCommitSectorParams -// TODO: This may need to be epoch-sensitive -func PreferredSealProofTypeFromWindowPoStType(proof abi.RegisteredPoStProof) (abi.RegisteredSealProof, error) { +func PreferredSealProofTypeFromWindowPoStType(nver network.Version, proof abi.RegisteredPoStProof) (abi.RegisteredSealProof, error) { + // We added support for the new proofs in network version 7, and removed support for the old + // ones in network version 8. + if nver < network.Version7 { + switch proof { + case abi.RegisteredPoStProof_StackedDrgWindow2KiBV1: + return abi.RegisteredSealProof_StackedDrg2KiBV1, nil + case abi.RegisteredPoStProof_StackedDrgWindow8MiBV1: + return abi.RegisteredSealProof_StackedDrg8MiBV1, nil + case abi.RegisteredPoStProof_StackedDrgWindow512MiBV1: + return abi.RegisteredSealProof_StackedDrg512MiBV1, nil + case abi.RegisteredPoStProof_StackedDrgWindow32GiBV1: + return abi.RegisteredSealProof_StackedDrg32GiBV1, nil + case abi.RegisteredPoStProof_StackedDrgWindow64GiBV1: + return abi.RegisteredSealProof_StackedDrg64GiBV1, nil + default: + return -1, xerrors.Errorf("unrecognized window post type: %d", proof) + } + } + switch proof { case abi.RegisteredPoStProof_StackedDrgWindow2KiBV1: return abi.RegisteredSealProof_StackedDrg2KiBV1_1, nil diff --git a/extern/storage-sealing/sealing.go b/extern/storage-sealing/sealing.go index 2219d9d2c..f46403742 100644 --- a/extern/storage-sealing/sealing.go +++ b/extern/storage-sealing/sealing.go @@ -475,7 +475,12 @@ func (m *Sealing) currentSealProof(ctx context.Context) (abi.RegisteredSealProof return 0, err } - return miner.PreferredSealProofTypeFromWindowPoStType(mi.WindowPoStProofType) + ver, err := m.api.StateNetworkVersion(ctx, nil) + if err != nil { + return 0, err + } + + return miner.PreferredSealProofTypeFromWindowPoStType(ver, mi.WindowPoStProofType) } func (m *Sealing) minerSector(spt abi.RegisteredSealProof, num abi.SectorNumber) storage.SectorRef { diff --git a/markets/storageadapter/provider.go b/markets/storageadapter/provider.go index 6a06c46e3..90a659d34 100644 --- a/markets/storageadapter/provider.go +++ b/markets/storageadapter/provider.go @@ -7,8 +7,6 @@ import ( "io" "time" - miner2 "github.com/filecoin-project/lotus/chain/actors/builtin/miner" - "github.com/ipfs/go-cid" logging "github.com/ipfs/go-log/v2" "golang.org/x/xerrors" @@ -26,6 +24,7 @@ import ( "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/builtin/market" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/events" "github.com/filecoin-project/lotus/chain/events/state" "github.com/filecoin-project/lotus/chain/types" @@ -158,30 +157,36 @@ func (n *ProviderNodeAdapter) VerifySignature(ctx context.Context, sig crypto.Si return err == nil, err } -func (n *ProviderNodeAdapter) GetMinerWorkerAddress(ctx context.Context, miner address.Address, tok shared.TipSetToken) (address.Address, error) { +func (n *ProviderNodeAdapter) GetMinerWorkerAddress(ctx context.Context, maddr address.Address, tok shared.TipSetToken) (address.Address, error) { tsk, err := types.TipSetKeyFromBytes(tok) if err != nil { return address.Undef, err } - mi, err := n.StateMinerInfo(ctx, miner, tsk) + mi, err := n.StateMinerInfo(ctx, maddr, tsk) if err != nil { return address.Address{}, err } return mi.Worker, nil } -func (n *ProviderNodeAdapter) GetProofType(ctx context.Context, miner address.Address, tok shared.TipSetToken) (abi.RegisteredSealProof, error) { +func (n *ProviderNodeAdapter) GetProofType(ctx context.Context, maddr address.Address, tok shared.TipSetToken) (abi.RegisteredSealProof, error) { tsk, err := types.TipSetKeyFromBytes(tok) if err != nil { return 0, err } - mi, err := n.StateMinerInfo(ctx, miner, tsk) + mi, err := n.StateMinerInfo(ctx, maddr, tsk) if err != nil { return 0, err } - return miner2.PreferredSealProofTypeFromWindowPoStType(mi.WindowPoStProofType) + + nver, err := n.StateNetworkVersion(ctx, tsk) + if err != nil { + return 0, err + } + + return miner.PreferredSealProofTypeFromWindowPoStType(nver, mi.WindowPoStProofType) } func (n *ProviderNodeAdapter) SignBytes(ctx context.Context, signer address.Address, b []byte) (*crypto.Signature, error) { diff --git a/node/impl/client/client.go b/node/impl/client/client.go index 3868e69ea..00c840b63 100644 --- a/node/impl/client/client.go +++ b/node/impl/client/client.go @@ -159,7 +159,12 @@ func (a *API) ClientStartDeal(ctx context.Context, params *api.StartDealParams) dealStart = ts.Height() + abi.ChainEpoch(dealStartBufferHours*blocksPerHour) // TODO: Get this from storage ask } - st, err := miner.PreferredSealProofTypeFromWindowPoStType(mi.WindowPoStProofType) + networkVersion, err := a.StateNetworkVersion(ctx, types.EmptyTSK) + if err != nil { + return nil, xerrors.Errorf("failed to get network version: %w", err) + } + + st, err := miner.PreferredSealProofTypeFromWindowPoStType(networkVersion, mi.WindowPoStProofType) if err != nil { return nil, xerrors.Errorf("failed to get seal proof type: %w", err) } diff --git a/node/modules/storageminer.go b/node/modules/storageminer.go index 165e98e01..2a0b3f8b2 100644 --- a/node/modules/storageminer.go +++ b/node/modules/storageminer.go @@ -10,8 +10,6 @@ import ( "path/filepath" "time" - miner2 "github.com/filecoin-project/lotus/chain/actors/builtin/miner" - "go.uber.org/fx" "go.uber.org/multierr" "golang.org/x/xerrors" @@ -60,6 +58,7 @@ import ( lapi "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors/builtin" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/gen" "github.com/filecoin-project/lotus/chain/gen/slashfilter" "github.com/filecoin-project/lotus/chain/types" @@ -68,7 +67,7 @@ import ( "github.com/filecoin-project/lotus/markets" marketevents "github.com/filecoin-project/lotus/markets/loggers" "github.com/filecoin-project/lotus/markets/retrievaladapter" - "github.com/filecoin-project/lotus/miner" + lotusminer "github.com/filecoin-project/lotus/miner" "github.com/filecoin-project/lotus/node/config" "github.com/filecoin-project/lotus/node/modules/dtypes" "github.com/filecoin-project/lotus/node/modules/helpers" @@ -129,8 +128,12 @@ func SealProofType(maddr dtypes.MinerAddress, fnapi lapi.FullNode) (abi.Register if err != nil { return 0, err } + networkVersion, err := fnapi.StateNetworkVersion(context.TODO(), types.EmptyTSK) + if err != nil { + return 0, err + } - return miner2.PreferredSealProofTypeFromWindowPoStType(mi.WindowPoStProofType) + return miner.PreferredSealProofTypeFromWindowPoStType(networkVersion, mi.WindowPoStProofType) } type sidsc struct { @@ -421,13 +424,13 @@ func StagingGraphsync(mctx helpers.MetricsCtx, lc fx.Lifecycle, ibs dtypes.Stagi return gs } -func SetupBlockProducer(lc fx.Lifecycle, ds dtypes.MetadataDS, api lapi.FullNode, epp gen.WinningPoStProver, sf *slashfilter.SlashFilter, j journal.Journal) (*miner.Miner, error) { +func SetupBlockProducer(lc fx.Lifecycle, ds dtypes.MetadataDS, api lapi.FullNode, epp gen.WinningPoStProver, sf *slashfilter.SlashFilter, j journal.Journal) (*lotusminer.Miner, error) { minerAddr, err := minerAddrFromDS(ds) if err != nil { return nil, err } - m := miner.NewMiner(api, epp, minerAddr, sf, j) + m := lotusminer.NewMiner(api, epp, minerAddr, sf, j) lc.Append(fx.Hook{ OnStart: func(ctx context.Context) error { From bf48728875ec26d6845557f6a5ea5d5a62d3dc8b Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 19 Jan 2021 18:21:23 -0800 Subject: [PATCH 35/58] move winning post proof type logic into a helper --- chain/actors/builtin/miner/miner.go | 17 +++++++++++++++++ chain/stmgr/utils.go | 18 +++--------------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index 3364f6195..713863fd0 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -186,6 +186,23 @@ func PreferredSealProofTypeFromWindowPoStType(nver network.Version, proof abi.Re } } +func WinningPoStProofTypeFromWindowPoStProofType(nver network.Version, proof abi.RegisteredPoStProof) (abi.RegisteredPoStProof, error) { + switch proof { + case abi.RegisteredPoStProof_StackedDrgWindow2KiBV1: + return abi.RegisteredPoStProof_StackedDrgWinning2KiBV1, nil + case abi.RegisteredPoStProof_StackedDrgWindow8MiBV1: + return abi.RegisteredPoStProof_StackedDrgWinning8MiBV1, nil + case abi.RegisteredPoStProof_StackedDrgWindow512MiBV1: + return abi.RegisteredPoStProof_StackedDrgWinning512MiBV1, nil + case abi.RegisteredPoStProof_StackedDrgWindow32GiBV1: + return abi.RegisteredPoStProof_StackedDrgWinning32GiBV1, nil + case abi.RegisteredPoStProof_StackedDrgWindow64GiBV1: + return abi.RegisteredPoStProof_StackedDrgWinning64GiBV1, nil + default: + return -1, xerrors.Errorf("unknown proof type %d", proof) + } +} + type MinerInfo struct { Owner address.Address // Must be an ID-address. Worker address.Address // Must be an ID-address. diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index d7bc42648..0fc104b5b 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -212,21 +212,9 @@ func GetSectorsForWinningPoSt(ctx context.Context, nv network.Version, pv ffiwra return nil, xerrors.Errorf("getting miner ID: %w", err) } - // TODO: move this to somewhere in specs-actors or the state types. - var proofType abi.RegisteredPoStProof - switch info.WindowPoStProofType { - case abi.RegisteredPoStProof_StackedDrgWindow2KiBV1: - proofType = abi.RegisteredPoStProof_StackedDrgWinning2KiBV1 - case abi.RegisteredPoStProof_StackedDrgWindow8MiBV1: - proofType = abi.RegisteredPoStProof_StackedDrgWinning8MiBV1 - case abi.RegisteredPoStProof_StackedDrgWindow512MiBV1: - proofType = abi.RegisteredPoStProof_StackedDrgWinning512MiBV1 - case abi.RegisteredPoStProof_StackedDrgWindow32GiBV1: - proofType = abi.RegisteredPoStProof_StackedDrgWinning32GiBV1 - case abi.RegisteredPoStProof_StackedDrgWindow64GiBV1: - proofType = abi.RegisteredPoStProof_StackedDrgWinning64GiBV1 - default: - return nil, xerrors.Errorf("unknown proof type %d", info.WindowPoStProofType) + proofType, err := miner.WinningPoStProofTypeFromWindowPoStProofType(nv, info.WindowPoStProofType) + if err != nil { + return nil, xerrors.Errorf("determining winning post proof type: %w", err) } ids, err := pv.GenerateWinningPoStSectorChallenge(ctx, proofType, abi.ActorID(mid), rand, numProvSect) From f1719d1e23de840569907d1825c7419f8a807d5c Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 19 Jan 2021 18:31:50 -0800 Subject: [PATCH 36/58] mark v3 as expensive --- chain/stmgr/forks.go | 1 + 1 file changed, 1 insertion(+) diff --git a/chain/stmgr/forks.go b/chain/stmgr/forks.go index c87b384ba..e09744a67 100644 --- a/chain/stmgr/forks.go +++ b/chain/stmgr/forks.go @@ -121,6 +121,7 @@ func DefaultUpgradeSchedule() UpgradeSchedule { Height: build.UpgradeActorsV3Height, Network: network.Version10, Migration: UpgradeActorsV3, + Expensive: true, }} for _, u := range updates { From fe5b5702f953273b1e91b23960e15e2ac6e38d76 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 20 Jan 2021 14:43:19 -0800 Subject: [PATCH 37/58] fix data race in test --- chain/sync_manager_test.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/chain/sync_manager_test.go b/chain/sync_manager_test.go index a5ff033ac..5f23e67c0 100644 --- a/chain/sync_manager_test.go +++ b/chain/sync_manager_test.go @@ -150,8 +150,11 @@ func TestSyncManagerEdgeCase(t *testing.T) { t.Fatalf("Expected tipset %s to sync, but got %s", e1, last) } - if len(sm.state) != 0 { - t.Errorf("active syncs expected empty but got: %d", len(sm.state)) + sm.mx.Lock() + activeSyncs := len(sm.state) + sm.mx.Unlock() + if activeSyncs != 0 { + t.Errorf("active syncs expected empty but got: %d", activeSyncs) } }) } From 026d236252435754af096ae6d72b091cf9a3a9ed Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 20 Jan 2021 18:17:41 -0800 Subject: [PATCH 38/58] more reliably close in tests --- cmd/lotus-gateway/endtoend_test.go | 2 +- node/test/builder.go | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/cmd/lotus-gateway/endtoend_test.go b/cmd/lotus-gateway/endtoend_test.go index 4d5e88c82..b6d81efb4 100644 --- a/cmd/lotus-gateway/endtoend_test.go +++ b/cmd/lotus-gateway/endtoend_test.go @@ -245,7 +245,7 @@ func startNodes( // Create a gateway server in front of the full node gapiImpl := newGatewayAPI(fullNode, lookbackCap, stateWaitLookbackLimit) - _, addr, err := builder.CreateRPCServer(gapiImpl) + _, addr, err := builder.CreateRPCServer(t, gapiImpl) require.NoError(t, err) // Create a gateway client API that connects to the gateway server diff --git a/node/test/builder.go b/node/test/builder.go index f6599cf23..7a754fd59 100644 --- a/node/test/builder.go +++ b/node/test/builder.go @@ -491,34 +491,40 @@ func mockSbBuilderOpts(t *testing.T, fullOpts []test.FullNodeOpts, storage []tes } func fullRpc(t *testing.T, nd test.TestNode) test.TestNode { - ma, listenAddr, err := CreateRPCServer(nd) + ma, listenAddr, err := CreateRPCServer(t, nd) require.NoError(t, err) + var stop func() var full test.TestNode - full.FullNode, _, err = client.NewFullNodeRPC(context.Background(), listenAddr, nil) + full.FullNode, stop, err = client.NewFullNodeRPC(context.Background(), listenAddr, nil) require.NoError(t, err) + t.Cleanup(stop) full.ListenAddr = ma return full } func storerRpc(t *testing.T, nd test.TestStorageNode) test.TestStorageNode { - ma, listenAddr, err := CreateRPCServer(nd) + ma, listenAddr, err := CreateRPCServer(t, nd) require.NoError(t, err) + var stop func() var storer test.TestStorageNode - storer.StorageMiner, _, err = client.NewStorageMinerRPC(context.Background(), listenAddr, nil) + storer.StorageMiner, stop, err = client.NewStorageMinerRPC(context.Background(), listenAddr, nil) require.NoError(t, err) + t.Cleanup(stop) storer.ListenAddr = ma storer.MineOne = nd.MineOne return storer } -func CreateRPCServer(handler interface{}) (multiaddr.Multiaddr, string, error) { +func CreateRPCServer(t *testing.T, handler interface{}) (multiaddr.Multiaddr, string, error) { rpcServer := jsonrpc.NewServer() rpcServer.Register("Filecoin", handler) testServ := httptest.NewServer(rpcServer) // todo: close + t.Cleanup(testServ.Close) + t.Cleanup(testServ.CloseClientConnections) addr := testServ.Listener.Addr() listenAddr := "ws://" + addr.String() From ab4f135208481c86b7c7bfc31a2a12d2cccb72ed Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 21 Jan 2021 10:00:35 -0800 Subject: [PATCH 39/58] test actors v3 --- api/test/ccupgrade.go | 2 +- api/test/test.go | 13 +++++++++---- api/test/window_post.go | 4 ++-- cmd/lotus-storage-miner/actor_test.go | 2 +- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/api/test/ccupgrade.go b/api/test/ccupgrade.go index eedcec6ca..2518d0ef9 100644 --- a/api/test/ccupgrade.go +++ b/api/test/ccupgrade.go @@ -31,7 +31,7 @@ func TestCCUpgrade(t *testing.T, b APIBuilder, blocktime time.Duration) { func testCCUpgrade(t *testing.T, b APIBuilder, blocktime time.Duration, upgradeHeight abi.ChainEpoch) { ctx := context.Background() - n, sn := b(t, []FullNodeOpts{FullNodeWithActorsV2At(upgradeHeight)}, OneMiner) + n, sn := b(t, []FullNodeOpts{FullNodeWithActorsV3At(upgradeHeight)}, OneMiner) client := n[0].FullNode.(*impl.FullNodeAPI) miner := sn[0] diff --git a/api/test/test.go b/api/test/test.go index a1b82c590..fed24d071 100644 --- a/api/test/test.go +++ b/api/test/test.go @@ -109,14 +109,19 @@ var OneMiner = []StorageMiner{{Full: 0, Preseal: PresealGenesis}} var OneFull = DefaultFullOpts(1) var TwoFull = DefaultFullOpts(2) -var FullNodeWithActorsV2At = func(upgradeHeight abi.ChainEpoch) FullNodeOpts { +var FullNodeWithActorsV3At = func(upgradeHeight abi.ChainEpoch) FullNodeOpts { return FullNodeOpts{ Opts: func(nodes []TestNode) node.Option { return node.Override(new(stmgr.UpgradeSchedule), stmgr.UpgradeSchedule{{ - // Skip directly to tape height so precommits work. - Network: network.Version5, - Height: upgradeHeight, + // prepare for upgrade. + Network: network.Version9, + Height: 1, Migration: stmgr.UpgradeActorsV2, + }, { + // Skip directly to tape height so precommits work. + Network: network.Version10, + Height: upgradeHeight, + Migration: stmgr.UpgradeActorsV3, }}) }, } diff --git a/api/test/window_post.go b/api/test/window_post.go index 84d668c76..0a7940513 100644 --- a/api/test/window_post.go +++ b/api/test/window_post.go @@ -218,7 +218,7 @@ func testWindowPostUpgrade(t *testing.T, b APIBuilder, blocktime time.Duration, ctx, cancel := context.WithCancel(context.Background()) defer cancel() - n, sn := b(t, []FullNodeOpts{FullNodeWithActorsV2At(upgradeHeight)}, OneMiner) + n, sn := b(t, []FullNodeOpts{FullNodeWithActorsV3At(upgradeHeight)}, OneMiner) client := n[0].FullNode.(*impl.FullNodeAPI) miner := sn[0] @@ -437,7 +437,7 @@ func TestTerminate(t *testing.T, b APIBuilder, blocktime time.Duration) { nSectors := uint64(2) - n, sn := b(t, []FullNodeOpts{FullNodeWithActorsV2At(1)}, []StorageMiner{{Full: 0, Preseal: int(nSectors)}}) + n, sn := b(t, []FullNodeOpts{FullNodeWithActorsV3At(1)}, []StorageMiner{{Full: 0, Preseal: int(nSectors)}}) client := n[0].FullNode.(*impl.FullNodeAPI) miner := sn[0] diff --git a/cmd/lotus-storage-miner/actor_test.go b/cmd/lotus-storage-miner/actor_test.go index 2aea6bda9..c478c3236 100644 --- a/cmd/lotus-storage-miner/actor_test.go +++ b/cmd/lotus-storage-miner/actor_test.go @@ -50,7 +50,7 @@ func TestWorkerKeyChange(t *testing.T) { blocktime := 1 * time.Millisecond - n, sn := builder.MockSbBuilder(t, []test.FullNodeOpts{test.FullNodeWithActorsV2At(1), test.FullNodeWithActorsV2At(1)}, test.OneMiner) + n, sn := builder.MockSbBuilder(t, []test.FullNodeOpts{test.FullNodeWithActorsV3At(1), test.FullNodeWithActorsV3At(1)}, test.OneMiner) client1 := n[0] client2 := n[1] From a1e6781f0c443b1337d4871bc644c1c20c48cb5b Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 21 Jan 2021 10:06:56 -0800 Subject: [PATCH 40/58] fix tests --- cmd/lotus-storage-miner/actor_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/lotus-storage-miner/actor_test.go b/cmd/lotus-storage-miner/actor_test.go index c478c3236..1816c1eab 100644 --- a/cmd/lotus-storage-miner/actor_test.go +++ b/cmd/lotus-storage-miner/actor_test.go @@ -50,7 +50,7 @@ func TestWorkerKeyChange(t *testing.T) { blocktime := 1 * time.Millisecond - n, sn := builder.MockSbBuilder(t, []test.FullNodeOpts{test.FullNodeWithActorsV3At(1), test.FullNodeWithActorsV3At(1)}, test.OneMiner) + n, sn := builder.MockSbBuilder(t, []test.FullNodeOpts{test.FullNodeWithActorsV3At(2), test.FullNodeWithActorsV3At(2)}, test.OneMiner) client1 := n[0] client2 := n[1] From 6ce5f2736e66a23de249f4298d8e4c9912f2f570 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 21 Jan 2021 10:44:13 -0800 Subject: [PATCH 41/58] update policy for v3 --- api/test/ccupgrade.go | 2 +- chain/actors/policy/policy.go | 47 +++++++++++++++++++++++++++++------ 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/api/test/ccupgrade.go b/api/test/ccupgrade.go index 2518d0ef9..88d3e6ed7 100644 --- a/api/test/ccupgrade.go +++ b/api/test/ccupgrade.go @@ -17,7 +17,7 @@ import ( func TestCCUpgrade(t *testing.T, b APIBuilder, blocktime time.Duration) { for _, height := range []abi.ChainEpoch{ - 1, // before + 2, // before 162, // while sealing 520, // after upgrade deal 5000, // after diff --git a/chain/actors/policy/policy.go b/chain/actors/policy/policy.go index 31d83cd3d..b1084bbcd 100644 --- a/chain/actors/policy/policy.go +++ b/chain/actors/policy/policy.go @@ -6,21 +6,28 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/lotus/chain/actors" + market0 "github.com/filecoin-project/specs-actors/actors/builtin/market" miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" power0 "github.com/filecoin-project/specs-actors/actors/builtin/power" verifreg0 "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" + builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" market2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/market" miner2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/miner" - paych2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/paych" verifreg2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/verifreg" + + builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" + market3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/market" + miner3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/miner" + paych3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/paych" + verifreg3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/verifreg" ) const ( - ChainFinality = miner0.ChainFinality + ChainFinality = miner3.ChainFinality SealRandomnessLookback = ChainFinality - PaychSettleDelay = paych2.SettleDelay + PaychSettleDelay = paych3.SettleDelay ) // SetSupportedProofTypes sets supported proof types, across all actor versions. @@ -31,6 +38,11 @@ func SetSupportedProofTypes(types ...abi.RegisteredSealProof) { miner2.PreCommitSealProofTypesV7 = make(map[abi.RegisteredSealProof]struct{}, len(types)*2) miner2.PreCommitSealProofTypesV8 = make(map[abi.RegisteredSealProof]struct{}, len(types)) + // TODO: need to remove the extra version specs actors. + miner3.PreCommitSealProofTypesV7 = make(map[abi.RegisteredSealProof]struct{}, len(types)) + miner3.PreCommitSealProofTypesV0 = make(map[abi.RegisteredSealProof]struct{}, len(types)) + miner3.PreCommitSealProofTypesV8 = make(map[abi.RegisteredSealProof]struct{}, len(types)) + AddSupportedProofTypes(types...) } @@ -49,6 +61,13 @@ func AddSupportedProofTypes(types ...abi.RegisteredSealProof) { miner2.PreCommitSealProofTypesV7[t+abi.RegisteredSealProof_StackedDrg2KiBV1_1] = struct{}{} miner2.PreCommitSealProofTypesV8[t+abi.RegisteredSealProof_StackedDrg2KiBV1_1] = struct{}{} + + miner3.PreCommitSealProofTypesV0[t] = struct{}{} + + miner3.PreCommitSealProofTypesV7[t] = struct{}{} + miner3.PreCommitSealProofTypesV7[t+abi.RegisteredSealProof_StackedDrg2KiBV1_1] = struct{}{} + + miner3.PreCommitSealProofTypesV8[t+abi.RegisteredSealProof_StackedDrg2KiBV1_1] = struct{}{} } } @@ -58,6 +77,7 @@ func SetPreCommitChallengeDelay(delay abi.ChainEpoch) { // Set for all miner versions. miner0.PreCommitChallengeDelay = delay miner2.PreCommitChallengeDelay = delay + miner3.PreCommitChallengeDelay = delay } // TODO: this function shouldn't really exist. Instead, the API should expose the precommit delay. @@ -73,6 +93,10 @@ func SetConsensusMinerMinPower(p abi.StoragePower) { for _, policy := range builtin2.SealProofPolicies { policy.ConsensusMinerMinPower = p } + + for _, policy := range builtin3.PoStProofPolicies { + policy.ConsensusMinerMinPower = p + } } // SetMinVerifiedDealSize sets the minimum size of a verified deal. This should @@ -80,6 +104,7 @@ func SetConsensusMinerMinPower(p abi.StoragePower) { func SetMinVerifiedDealSize(size abi.StoragePower) { verifreg0.MinVerifiedDealSize = size verifreg2.MinVerifiedDealSize = size + verifreg3.MinVerifiedDealSize = size } func GetMaxProveCommitDuration(ver actors.Version, t abi.RegisteredSealProof) abi.ChainEpoch { @@ -88,6 +113,8 @@ func GetMaxProveCommitDuration(ver actors.Version, t abi.RegisteredSealProof) ab return miner0.MaxSealDuration[t] case actors.Version2: return miner2.MaxProveCommitDuration[t] + case actors.Version3: + return miner3.MaxProveCommitDuration[t] default: panic("unsupported actors version") } @@ -103,6 +130,8 @@ func DealProviderCollateralBounds( return market0.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil, nwVer) case actors.Version2: return market2.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil) + case actors.Version3: + return market3.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil) default: panic("unsupported network version") } @@ -116,6 +145,10 @@ func SetWPoStChallengeWindow(period abi.ChainEpoch) { miner2.WPoStChallengeWindow = period miner2.WPoStProvingPeriod = period * abi.ChainEpoch(miner2.WPoStPeriodDeadlines) + + // TODO: change dispute window as well? This is only used for testing anyways. + miner3.WPoStChallengeWindow = period + miner3.WPoStProvingPeriod = period * abi.ChainEpoch(miner3.WPoStPeriodDeadlines) } func GetWinningPoStSectorSetLookback(nwVer network.Version) abi.ChainEpoch { @@ -132,17 +165,17 @@ func GetMaxSectorExpirationExtension() abi.ChainEpoch { // TODO: we'll probably need to abstract over this better in the future. func GetMaxPoStPartitions(p abi.RegisteredPoStProof) (int, error) { - sectorsPerPart, err := builtin2.PoStProofWindowPoStPartitionSectors(p) + sectorsPerPart, err := builtin3.PoStProofWindowPoStPartitionSectors(p) if err != nil { return 0, err } - return int(miner2.AddressedSectorsMax / sectorsPerPart), nil + return int(miner3.AddressedSectorsMax / sectorsPerPart), nil } func GetDefaultSectorSize() abi.SectorSize { // supported sector sizes are the same across versions. - szs := make([]abi.SectorSize, 0, len(miner2.PreCommitSealProofTypesV8)) - for spt := range miner2.PreCommitSealProofTypesV8 { + szs := make([]abi.SectorSize, 0, len(miner3.PreCommitSealProofTypesV8)) + for spt := range miner3.PreCommitSealProofTypesV8 { ss, err := spt.SectorSize() if err != nil { panic(err) From b00efcd701fa486bb91013247c08a54c5260fb46 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 21 Jan 2021 10:53:06 -0800 Subject: [PATCH 42/58] further fix tests --- api/test/window_post.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/test/window_post.go b/api/test/window_post.go index 0a7940513..d21224670 100644 --- a/api/test/window_post.go +++ b/api/test/window_post.go @@ -201,7 +201,7 @@ func pledgeSectors(t *testing.T, ctx context.Context, miner TestStorageNode, n, func TestWindowPost(t *testing.T, b APIBuilder, blocktime time.Duration, nSectors int) { for _, height := range []abi.ChainEpoch{ - 1, // before + 2, // before 162, // while sealing 5000, // while proving } { From c5d3b979cbbf61d4c686fe2a1da2bdfb2242d8ea Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 21 Jan 2021 11:24:05 -0800 Subject: [PATCH 43/58] fix constructing new actors --- chain/vm/mkactor.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/chain/vm/mkactor.go b/chain/vm/mkactor.go index 885d3c0db..072711db6 100644 --- a/chain/vm/mkactor.go +++ b/chain/vm/mkactor.go @@ -12,6 +12,7 @@ import ( builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" + builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" "github.com/filecoin-project/go-address" "github.com/filecoin-project/lotus/chain/actors/aerrors" @@ -91,6 +92,8 @@ func newAccountActor(ver actors.Version) *types.Actor { code = builtin0.AccountActorCodeID case actors.Version2: code = builtin2.AccountActorCodeID + case actors.Version3: + code = builtin3.AccountActorCodeID default: panic("unsupported actors version") } From 5a5e49dcd7c75d70aab9d6607b2e85e142273b11 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 21 Jan 2021 11:26:55 -0800 Subject: [PATCH 44/58] support paych v3 messages --- chain/actors/builtin/paych/message.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/chain/actors/builtin/paych/message.go b/chain/actors/builtin/paych/message.go index cfc8cbe71..39c091d45 100644 --- a/chain/actors/builtin/paych/message.go +++ b/chain/actors/builtin/paych/message.go @@ -19,6 +19,8 @@ func Message(version actors.Version, from address.Address) MessageBuilder { return message0{from} case actors.Version2: return message2{from} + case actors.Version3: + return message3{from} default: panic(fmt.Sprintf("unsupported actors version: %d", version)) } From f10b13ff32fb9e304e743733d033abe5b4a7dac6 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 21 Jan 2021 11:43:36 -0800 Subject: [PATCH 45/58] register v3 methods --- chain/stmgr/utils.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index 0fc104b5b..1d59b2630 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -25,6 +25,7 @@ import ( exported0 "github.com/filecoin-project/specs-actors/actors/builtin/exported" exported2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/exported" + exported3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/exported" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/chain/actors/builtin" @@ -560,6 +561,7 @@ func init() { var actors []rt.VMActor actors = append(actors, exported0.BuiltinActors()...) actors = append(actors, exported2.BuiltinActors()...) + actors = append(actors, exported3.BuiltinActors()...) for _, actor := range actors { exports := actor.Exports() From bd00c505b27f3d525116c35925bb21d48bc6a7b6 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 21 Jan 2021 12:17:43 -0800 Subject: [PATCH 46/58] fix upgrade epoch for termiante test --- api/test/window_post.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/test/window_post.go b/api/test/window_post.go index d21224670..3a39c8422 100644 --- a/api/test/window_post.go +++ b/api/test/window_post.go @@ -437,7 +437,7 @@ func TestTerminate(t *testing.T, b APIBuilder, blocktime time.Duration) { nSectors := uint64(2) - n, sn := b(t, []FullNodeOpts{FullNodeWithActorsV3At(1)}, []StorageMiner{{Full: 0, Preseal: int(nSectors)}}) + n, sn := b(t, []FullNodeOpts{FullNodeWithActorsV3At(2)}, []StorageMiner{{Full: 0, Preseal: int(nSectors)}}) client := n[0].FullNode.(*impl.FullNodeAPI) miner := sn[0] From c27ec4ed221673507fa2fe824a794a0a8ee35792 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 21 Jan 2021 14:57:51 -0800 Subject: [PATCH 47/58] latest specs actors master --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 164977133..abb4caa36 100644 --- a/go.mod +++ b/go.mod @@ -44,7 +44,7 @@ require ( github.com/filecoin-project/go-storedcounter v0.0.0-20200421200003-1c99c62e8a5b github.com/filecoin-project/specs-actors v0.9.13 github.com/filecoin-project/specs-actors/v2 v2.3.4 - github.com/filecoin-project/specs-actors/v3 v3.0.0 + github.com/filecoin-project/specs-actors/v3 v3.0.1-0.20210121225528-86a310df1e63 github.com/filecoin-project/specs-storage v0.1.1-0.20201105051918-5188d9774506 github.com/filecoin-project/test-vectors/schema v0.0.5 github.com/gbrlsnchs/jwt/v3 v3.0.0-beta.1 diff --git a/go.sum b/go.sum index 18eb13fe0..e992f4af2 100644 --- a/go.sum +++ b/go.sum @@ -307,8 +307,8 @@ github.com/filecoin-project/specs-actors/v2 v2.3.2 h1:2Vcf4CGa29kRh4JJ02m+FbvD/p github.com/filecoin-project/specs-actors/v2 v2.3.2/go.mod h1:UuJQLoTx/HPvvWeqlIFmC/ywlOLHNe8SNQ3OunFbu2Y= github.com/filecoin-project/specs-actors/v2 v2.3.4 h1:NZK2oMCcA71wNsUzDBmLQyRMzcCnX9tDGvwZ53G67j8= github.com/filecoin-project/specs-actors/v2 v2.3.4/go.mod h1:UuJQLoTx/HPvvWeqlIFmC/ywlOLHNe8SNQ3OunFbu2Y= -github.com/filecoin-project/specs-actors/v3 v3.0.0 h1:hX5LrLSmZsSAV+VoDYucEpiy8Iv3arF+9Lc4Ig7VlXM= -github.com/filecoin-project/specs-actors/v3 v3.0.0/go.mod h1:aVf248CfjfyCmVel4UuFAA3u+9UQjqtqHpgfYv+M+9U= +github.com/filecoin-project/specs-actors/v3 v3.0.1-0.20210121225528-86a310df1e63 h1:p7uz0gVvPktp//n6dW5Mx/a2zOGTLfA7LdqL6sAeJY8= +github.com/filecoin-project/specs-actors/v3 v3.0.1-0.20210121225528-86a310df1e63/go.mod h1:aVf248CfjfyCmVel4UuFAA3u+9UQjqtqHpgfYv+M+9U= github.com/filecoin-project/specs-storage v0.1.1-0.20201105051918-5188d9774506 h1:Ur/l2+6qN+lQiqjozWWc5p9UDaAMDZKTlDS98oRnlIw= github.com/filecoin-project/specs-storage v0.1.1-0.20201105051918-5188d9774506/go.mod h1:nJRRM7Aa9XVvygr3W9k6xGF46RWzr2zxF/iGoAIfA/g= github.com/filecoin-project/test-vectors/schema v0.0.5 h1:w3zHQhzM4pYxJDl21avXjOKBLF8egrvwUwjpT8TquDg= From d412ccdb3f18571155f3fab3d192a8f47b43e5ba Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 21 Jan 2021 16:19:11 -0800 Subject: [PATCH 48/58] disable the watchdog It's causing the tests to flake. --- node/modules/core.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/modules/core.go b/node/modules/core.go index 83a7e8d42..aee6f2ea9 100644 --- a/node/modules/core.go +++ b/node/modules/core.go @@ -71,7 +71,7 @@ func MemoryConstraints() system.MemoryConstraints { // MemoryWatchdog starts the memory watchdog, applying the computed resource // constraints. func MemoryWatchdog(lr repo.LockedRepo, lc fx.Lifecycle, constraints system.MemoryConstraints) { - if os.Getenv(EnvWatchdogDisabled) == "1" { + if true || os.Getenv(EnvWatchdogDisabled) == "1" { log.Infof("memory watchdog is disabled via %s", EnvWatchdogDisabled) return } From 0ba13069690172ed6d5869e973d7ae6a4b542fa8 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 21 Jan 2021 19:48:34 -0800 Subject: [PATCH 49/58] test prove then dispute --- api/test/test.go | 1 + api/test/window_post.go | 207 ++++++++++++++++++++++++++++ chain/actors/builtin/miner/miner.go | 2 + node/node_test.go | 10 ++ node/test/builder.go | 2 +- 5 files changed, 221 insertions(+), 1 deletion(-) diff --git a/api/test/test.go b/api/test/test.go index fed24d071..f498cb974 100644 --- a/api/test/test.go +++ b/api/test/test.go @@ -48,6 +48,7 @@ type TestStorageNode struct { ListenAddr multiaddr.Multiaddr MineOne func(context.Context, miner.MineReq) error + Stop func(context.Context) error } var PresealGenesis = -1 diff --git a/api/test/window_post.go b/api/test/window_post.go index 3a39c8422..69a066121 100644 --- a/api/test/window_post.go +++ b/api/test/window_post.go @@ -16,13 +16,17 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/lotus/extern/sector-storage/mock" sealing "github.com/filecoin-project/lotus/extern/storage-sealing" + proof3 "github.com/filecoin-project/specs-actors/v3/actors/runtime/proof" "github.com/filecoin-project/specs-storage/storage" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" + "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" bminer "github.com/filecoin-project/lotus/miner" "github.com/filecoin-project/lotus/node/impl" @@ -602,3 +606,206 @@ loop: require.Equal(t, p.MinerPower, p.TotalPower) require.Equal(t, p.MinerPower.RawBytePower, types.NewInt(uint64(ssz)*(nSectors-1))) } + +func TestWindowPostDispute(t *testing.T, b APIBuilder, blocktime time.Duration) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + // First, we configure two miners. After sealing, we're going to turn off the first miner so + // it doesn't submit proofs. + /// + // Then we're going to manually submit bad proofs. + n, sn := b(t, []FullNodeOpts{ + FullNodeWithActorsV3At(2), + }, []StorageMiner{ + {Full: 0, Preseal: PresealGenesis}, + {Full: 0}, + }) + + client := n[0].FullNode.(*impl.FullNodeAPI) + chainMiner := sn[0] + evilMiner := sn[1] + + { + addrinfo, err := client.NetAddrsListen(ctx) + if err != nil { + t.Fatal(err) + } + + if err := chainMiner.NetConnect(ctx, addrinfo); err != nil { + t.Fatal(err) + } + + if err := evilMiner.NetConnect(ctx, addrinfo); err != nil { + t.Fatal(err) + } + } + + build.Clock.Sleep(time.Second) + + // Mine with the _second_ node (the good one). + done := make(chan struct{}) + go func() { + defer close(done) + for ctx.Err() == nil { + build.Clock.Sleep(blocktime) + if err := chainMiner.MineOne(ctx, MineNext); err != nil { + if ctx.Err() != nil { + // context was canceled, ignore the error. + return + } + t.Error(err) + } + } + }() + defer func() { + cancel() + <-done + }() + + // Give the chain miner enough sectors to win every block. + pledgeSectors(t, ctx, chainMiner, 10, 0, nil) + // And the evil one 1 sector. No cookie for you. + pledgeSectors(t, ctx, evilMiner, 1, 0, nil) + + // Let the evil miner's sectors gain power. + evilMinerAddr, err := evilMiner.ActorAddress(ctx) + require.NoError(t, err) + + di, err := client.StateMinerProvingDeadline(ctx, evilMinerAddr, types.EmptyTSK) + require.NoError(t, err) + + minerInfo, err := client.StateMinerInfo(ctx, evilMinerAddr, types.EmptyTSK) + require.NoError(t, err) + + fmt.Printf("Running one proving period\n") + fmt.Printf("End for head.Height > %d\n", di.PeriodStart+di.WPoStProvingPeriod*2) + + for { + head, err := client.ChainHead(ctx) + require.NoError(t, err) + + if head.Height() > di.PeriodStart+di.WPoStProvingPeriod*2 { + fmt.Printf("Now head.Height = %d\n", head.Height()) + break + } + build.Clock.Sleep(blocktime) + } + + p, err := client.StateMinerPower(ctx, evilMinerAddr, types.EmptyTSK) + require.NoError(t, err) + + ssz, err := evilMiner.ActorSectorSize(ctx, evilMinerAddr) + require.NoError(t, err) + + // make sure it has gained power. + require.Equal(t, p.MinerPower.RawBytePower, types.NewInt(uint64(ssz))) + + evilSectors, err := evilMiner.SectorsList(ctx) + require.NoError(t, err) + evilSectorNo := evilSectors[0] // only one. + evilSectorLoc, err := client.StateSectorPartition(ctx, evilMinerAddr, evilSectorNo, types.EmptyTSK) + require.NoError(t, err) + + fmt.Println("evil miner stopping") + + // Now stop the evil miner, and start manually submitting bad proofs. + require.NoError(t, evilMiner.Stop(ctx)) + + fmt.Println("evil miner stopped") + + // Wait until we need to prove our sector. + for { + di, err = client.StateMinerProvingDeadline(ctx, evilMinerAddr, types.EmptyTSK) + require.NoError(t, err) + if di.Index == evilSectorLoc.Deadline { + break + } + build.Clock.Sleep(blocktime) + } + + // submit a bad proof + { + fmt.Println("submitting evil proof") + head, err := client.ChainHead(ctx) + require.NoError(t, err) + + commEpoch := di.Open + commRand, err := client.ChainGetRandomnessFromTickets( + ctx, head.Key(), crypto.DomainSeparationTag_PoStChainCommit, + commEpoch, nil, + ) + require.NoError(t, err) + params := &miner.SubmitWindowedPoStParams{ + ChainCommitEpoch: commEpoch, + ChainCommitRand: commRand, + Deadline: evilSectorLoc.Deadline, + Partitions: []miner.PoStPartition{{Index: evilSectorLoc.Partition}}, + Proofs: []proof3.PoStProof{{ + PoStProof: minerInfo.WindowPoStProofType, + ProofBytes: []byte("I'm soooo very evil."), + }}, + } + + enc, aerr := actors.SerializeParams(params) + require.NoError(t, aerr) + + msg := &types.Message{ + To: evilMinerAddr, + Method: miner.Methods.SubmitWindowedPoSt, + Params: enc, + Value: types.NewInt(0), + From: minerInfo.Owner, + } + sm, err := client.MpoolPushMessage(ctx, msg, nil) + require.NoError(t, err) + + fmt.Println("waiting for evil proof") + rec, err := client.StateWaitMsg(ctx, sm.Cid(), build.MessageConfidence) + require.NoError(t, err) + require.Zero(t, rec.Receipt.ExitCode, "evil proof not accepted: %s", rec.Receipt.ExitCode.Error()) + } + + // Wait until after the proving period. + for { + di, err := client.StateMinerProvingDeadline(ctx, evilMinerAddr, types.EmptyTSK) + require.NoError(t, err) + if di.Index != evilSectorLoc.Deadline { + break + } + build.Clock.Sleep(blocktime) + } + + fmt.Println("accepted evil proof") + + // Make sure the evil node didn't lose any power. + p, err = client.StateMinerPower(ctx, evilMinerAddr, types.EmptyTSK) + require.NoError(t, err) + require.Equal(t, p.MinerPower.RawBytePower, types.NewInt(uint64(ssz))) + + // OBJECTION! The good miner files a DISPUTE!!!! + { + params := &miner.DisputeWindowedPoStParams{ + Deadline: evilSectorLoc.Deadline, + PoStIndex: 0, + } + + enc, aerr := actors.SerializeParams(params) + require.NoError(t, aerr) + + msg := &types.Message{ + To: evilMinerAddr, + Method: miner.Methods.DisputeWindowedPoSt, + Params: enc, + Value: types.NewInt(0), + From: minerInfo.Owner, // TODO: new miner... + } + sm, err := client.MpoolPushMessage(ctx, msg, nil) + require.NoError(t, err) + + fmt.Println("waiting dispute") + rec, err := client.StateWaitMsg(ctx, sm.Cid(), build.MessageConfidence) + require.NoError(t, err) + require.Zero(t, rec.Receipt.ExitCode, "dispute not accepted: %s", rec.Receipt.ExitCode.Error()) + } +} diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index 713863fd0..38a5085db 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -23,6 +23,7 @@ import ( builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" miner2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/miner" builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" + miner3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/miner" ) func init() { @@ -149,6 +150,7 @@ type DeclareFaultsParams = miner0.DeclareFaultsParams type DeclareFaultsRecoveredParams = miner0.DeclareFaultsRecoveredParams type SubmitWindowedPoStParams = miner0.SubmitWindowedPoStParams type ProveCommitSectorParams = miner0.ProveCommitSectorParams +type DisputeWindowedPoStParams = miner3.DisputeWindowedPoStParams func PreferredSealProofTypeFromWindowPoStType(nver network.Version, proof abi.RegisteredPoStProof) (abi.RegisteredSealProof, error) { // We added support for the new proofs in network version 7, and removed support for the old diff --git a/node/node_test.go b/node/node_test.go index ecc0914ae..aa4c9f904 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -198,3 +198,13 @@ func TestPaymentChannels(t *testing.T) { test.TestPaymentChannels(t, builder.MockSbBuilder, 5*time.Millisecond) } + +func TestWindowPostDispute(t *testing.T) { + logging.SetLogLevel("miner", "ERROR") + logging.SetLogLevel("chainstore", "ERROR") + logging.SetLogLevel("chain", "ERROR") + logging.SetLogLevel("sub", "ERROR") + logging.SetLogLevel("storageminer", "ERROR") + + test.TestWindowPostDispute(t, builder.MockSbBuilder, 2*time.Millisecond) +} diff --git a/node/test/builder.go b/node/test/builder.go index 7a754fd59..94ddf6a4a 100644 --- a/node/test/builder.go +++ b/node/test/builder.go @@ -148,7 +148,7 @@ func CreateTestStorageNode(ctx context.Context, t *testing.T, waddr address.Addr } } - return test.TestStorageNode{StorageMiner: minerapi, MineOne: mineOne} + return test.TestStorageNode{StorageMiner: minerapi, MineOne: mineOne, Stop: stop} } func Builder(t *testing.T, fullOpts []test.FullNodeOpts, storage []test.StorageMiner) ([]test.TestNode, []test.TestStorageNode) { From 1b67eed82c3b598915efebf56d3095aed7b54d68 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 21 Jan 2021 20:16:03 -0800 Subject: [PATCH 50/58] make the dispute test run by itself It's kind of slow. --- .circleci/config.yml | 5 +++++ node/node_test.go | 3 +++ 2 files changed, 8 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 41b18b048..dc58bf2e9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -591,6 +591,11 @@ workflows: go-test-flags: "-run=TestWindowedPost" winpost-test: "1" test-suite-name: window-post + - test-window-post: + codecov-upload: true + go-test-flags: "-run=TestWindowedDispute" + winpost-test: "1" + test-suite-name: window-post-dispute - test-terminate: codecov-upload: true go-test-flags: "-run=TestTerminate" diff --git a/node/node_test.go b/node/node_test.go index aa4c9f904..a44b0f3a8 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -200,6 +200,9 @@ func TestPaymentChannels(t *testing.T) { } func TestWindowPostDispute(t *testing.T) { + if os.Getenv("LOTUS_TEST_WINDOW_POST") != "1" { + t.Skip("this takes a few minutes, set LOTUS_TEST_WINDOW_POST=1 to run") + } logging.SetLogLevel("miner", "ERROR") logging.SetLogLevel("chainstore", "ERROR") logging.SetLogLevel("chain", "ERROR") From aa53f5b7d7300c1a02a617f351af48f42c3f2e12 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 22 Jan 2021 08:28:32 -0800 Subject: [PATCH 51/58] fix ci config --- .circleci/config.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index dc58bf2e9..b422a1146 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -201,6 +201,8 @@ jobs: <<: *test test-window-post: <<: *test + test-window-post-dispute: + <<: *test test-terminate: <<: *test test-conformance: @@ -591,7 +593,7 @@ workflows: go-test-flags: "-run=TestWindowedPost" winpost-test: "1" test-suite-name: window-post - - test-window-post: + - test-window-post-dispute: codecov-upload: true go-test-flags: "-run=TestWindowedDispute" winpost-test: "1" From 9e63e5979e076c9427bd4ab40c59d9d6c20cbdd2 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 22 Jan 2021 08:29:00 -0800 Subject: [PATCH 52/58] test that the dispute worked, then recover --- api/test/window_post.go | 97 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 96 insertions(+), 1 deletion(-) diff --git a/api/test/window_post.go b/api/test/window_post.go index 69a066121..17225137d 100644 --- a/api/test/window_post.go +++ b/api/test/window_post.go @@ -768,7 +768,7 @@ func TestWindowPostDispute(t *testing.T, b APIBuilder, blocktime time.Duration) // Wait until after the proving period. for { - di, err := client.StateMinerProvingDeadline(ctx, evilMinerAddr, types.EmptyTSK) + di, err = client.StateMinerProvingDeadline(ctx, evilMinerAddr, types.EmptyTSK) require.NoError(t, err) if di.Index != evilSectorLoc.Deadline { break @@ -808,4 +808,99 @@ func TestWindowPostDispute(t *testing.T, b APIBuilder, blocktime time.Duration) require.NoError(t, err) require.Zero(t, rec.Receipt.ExitCode, "dispute not accepted: %s", rec.Receipt.ExitCode.Error()) } + + // Objection SUSTAINED! + // Make sure the evil node lost power. + p, err = client.StateMinerPower(ctx, evilMinerAddr, types.EmptyTSK) + require.NoError(t, err) + require.True(t, p.MinerPower.RawBytePower.IsZero()) + + // Now we begin the redemption arc. + require.True(t, p.MinerPower.RawBytePower.IsZero()) + + // First, recover the sector. + + { + params := &miner.DeclareFaultsRecoveredParams{ + Recoveries: []miner.RecoveryDeclaration{{ + Deadline: evilSectorLoc.Deadline, + Partition: evilSectorLoc.Partition, + Sectors: bitfield.NewFromSet([]uint64{uint64(evilSectorNo)}), + }}, + } + + enc, aerr := actors.SerializeParams(params) + require.NoError(t, aerr) + + msg := &types.Message{ + To: evilMinerAddr, + Method: miner.Methods.DeclareFaultsRecovered, + Params: enc, + Value: types.NewInt(0), + From: minerInfo.Owner, // TODO: new miner... + } + sm, err := client.MpoolPushMessage(ctx, msg, nil) + require.NoError(t, err) + + rec, err := client.StateWaitMsg(ctx, sm.Cid(), build.MessageConfidence) + require.NoError(t, err) + require.Zero(t, rec.Receipt.ExitCode, "recovery not accepted: %s", rec.Receipt.ExitCode.Error()) + } + + // Then wait for the deadline. + for { + di, err = client.StateMinerProvingDeadline(ctx, evilMinerAddr, types.EmptyTSK) + require.NoError(t, err) + if di.Index == evilSectorLoc.Deadline { + break + } + build.Clock.Sleep(blocktime) + } + + // And prove it. + { + fmt.Println("submitting good proof") + head, err := client.ChainHead(ctx) + require.NoError(t, err) + + commEpoch := di.Open + commRand, err := client.ChainGetRandomnessFromTickets( + ctx, head.Key(), crypto.DomainSeparationTag_PoStChainCommit, + commEpoch, nil, + ) + require.NoError(t, err) + params := &miner.SubmitWindowedPoStParams{ + ChainCommitEpoch: commEpoch, + ChainCommitRand: commRand, + Deadline: evilSectorLoc.Deadline, + Partitions: []miner.PoStPartition{{Index: evilSectorLoc.Partition}}, + Proofs: []proof3.PoStProof{{ + PoStProof: minerInfo.WindowPoStProofType, + ProofBytes: []byte("I'm soooo very evil."), + }}, + } + + enc, aerr := actors.SerializeParams(params) + require.NoError(t, aerr) + + msg := &types.Message{ + To: evilMinerAddr, + Method: miner.Methods.SubmitWindowedPoSt, + Params: enc, + Value: types.NewInt(0), + From: minerInfo.Owner, + } + sm, err := client.MpoolPushMessage(ctx, msg, nil) + require.NoError(t, err) + + fmt.Println("waiting for evil proof") + rec, err := client.StateWaitMsg(ctx, sm.Cid(), build.MessageConfidence) + require.NoError(t, err) + require.Zero(t, rec.Receipt.ExitCode, "evil proof not accepted: %s", rec.Receipt.ExitCode.Error()) + } + + // The power should be restored. + p, err = client.StateMinerPower(ctx, evilMinerAddr, types.EmptyTSK) + require.NoError(t, err) + require.Equal(t, p.MinerPower.RawBytePower, types.NewInt(uint64(ssz))) } From cc423ee4d29a554148c37bd9cfe13e3e8f9cadac Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 22 Jan 2021 08:30:58 -0800 Subject: [PATCH 53/58] fix seal types length --- chain/actors/policy/policy.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chain/actors/policy/policy.go b/chain/actors/policy/policy.go index b1084bbcd..6086a8e40 100644 --- a/chain/actors/policy/policy.go +++ b/chain/actors/policy/policy.go @@ -39,8 +39,8 @@ func SetSupportedProofTypes(types ...abi.RegisteredSealProof) { miner2.PreCommitSealProofTypesV8 = make(map[abi.RegisteredSealProof]struct{}, len(types)) // TODO: need to remove the extra version specs actors. - miner3.PreCommitSealProofTypesV7 = make(map[abi.RegisteredSealProof]struct{}, len(types)) miner3.PreCommitSealProofTypesV0 = make(map[abi.RegisteredSealProof]struct{}, len(types)) + miner3.PreCommitSealProofTypesV7 = make(map[abi.RegisteredSealProof]struct{}, len(types)*2) miner3.PreCommitSealProofTypesV8 = make(map[abi.RegisteredSealProof]struct{}, len(types)) AddSupportedProofTypes(types...) From 9e611d5f4d3de48b71b6e74493a1a2fd2588779b Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 22 Jan 2021 09:34:15 -0800 Subject: [PATCH 54/58] test evil post on recover --- api/test/window_post.go | 170 +++++++++++++++++++--------------------- 1 file changed, 81 insertions(+), 89 deletions(-) diff --git a/api/test/window_post.go b/api/test/window_post.go index 17225137d..42ada189d 100644 --- a/api/test/window_post.go +++ b/api/test/window_post.go @@ -17,6 +17,7 @@ import ( "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/crypto" + "github.com/filecoin-project/go-state-types/dline" "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/lotus/extern/sector-storage/mock" sealing "github.com/filecoin-project/lotus/extern/storage-sealing" @@ -641,6 +642,9 @@ func TestWindowPostDispute(t *testing.T, b APIBuilder, blocktime time.Duration) } } + defaultFrom, err := client.WalletDefaultAddress(ctx) + require.NoError(t, err) + build.Clock.Sleep(time.Second) // Mine with the _second_ node (the good one). @@ -675,9 +679,6 @@ func TestWindowPostDispute(t *testing.T, b APIBuilder, blocktime time.Duration) di, err := client.StateMinerProvingDeadline(ctx, evilMinerAddr, types.EmptyTSK) require.NoError(t, err) - minerInfo, err := client.StateMinerInfo(ctx, evilMinerAddr, types.EmptyTSK) - require.NoError(t, err) - fmt.Printf("Running one proving period\n") fmt.Printf("End for head.Height > %d\n", di.PeriodStart+di.WPoStProvingPeriod*2) @@ -724,47 +725,8 @@ func TestWindowPostDispute(t *testing.T, b APIBuilder, blocktime time.Duration) build.Clock.Sleep(blocktime) } - // submit a bad proof - { - fmt.Println("submitting evil proof") - head, err := client.ChainHead(ctx) - require.NoError(t, err) - - commEpoch := di.Open - commRand, err := client.ChainGetRandomnessFromTickets( - ctx, head.Key(), crypto.DomainSeparationTag_PoStChainCommit, - commEpoch, nil, - ) - require.NoError(t, err) - params := &miner.SubmitWindowedPoStParams{ - ChainCommitEpoch: commEpoch, - ChainCommitRand: commRand, - Deadline: evilSectorLoc.Deadline, - Partitions: []miner.PoStPartition{{Index: evilSectorLoc.Partition}}, - Proofs: []proof3.PoStProof{{ - PoStProof: minerInfo.WindowPoStProofType, - ProofBytes: []byte("I'm soooo very evil."), - }}, - } - - enc, aerr := actors.SerializeParams(params) - require.NoError(t, aerr) - - msg := &types.Message{ - To: evilMinerAddr, - Method: miner.Methods.SubmitWindowedPoSt, - Params: enc, - Value: types.NewInt(0), - From: minerInfo.Owner, - } - sm, err := client.MpoolPushMessage(ctx, msg, nil) - require.NoError(t, err) - - fmt.Println("waiting for evil proof") - rec, err := client.StateWaitMsg(ctx, sm.Cid(), build.MessageConfidence) - require.NoError(t, err) - require.Zero(t, rec.Receipt.ExitCode, "evil proof not accepted: %s", rec.Receipt.ExitCode.Error()) - } + err = submitBadProof(ctx, client, evilMinerAddr, di, evilSectorLoc.Deadline, evilSectorLoc.Partition) + require.NoError(t, err, "evil proof not accepted") // Wait until after the proving period. for { @@ -798,7 +760,7 @@ func TestWindowPostDispute(t *testing.T, b APIBuilder, blocktime time.Duration) Method: miner.Methods.DisputeWindowedPoSt, Params: enc, Value: types.NewInt(0), - From: minerInfo.Owner, // TODO: new miner... + From: defaultFrom, // TODO: new miner... } sm, err := client.MpoolPushMessage(ctx, msg, nil) require.NoError(t, err) @@ -807,6 +769,7 @@ func TestWindowPostDispute(t *testing.T, b APIBuilder, blocktime time.Duration) rec, err := client.StateWaitMsg(ctx, sm.Cid(), build.MessageConfidence) require.NoError(t, err) require.Zero(t, rec.Receipt.ExitCode, "dispute not accepted: %s", rec.Receipt.ExitCode.Error()) + fmt.Println("GASS!!!: ", rec.Receipt.GasUsed) } // Objection SUSTAINED! @@ -821,6 +784,9 @@ func TestWindowPostDispute(t *testing.T, b APIBuilder, blocktime time.Duration) // First, recover the sector. { + minerInfo, err := client.StateMinerInfo(ctx, evilMinerAddr, types.EmptyTSK) + require.NoError(t, err) + params := &miner.DeclareFaultsRecoveredParams{ Recoveries: []miner.RecoveryDeclaration{{ Deadline: evilSectorLoc.Deadline, @@ -836,8 +802,8 @@ func TestWindowPostDispute(t *testing.T, b APIBuilder, blocktime time.Duration) To: evilMinerAddr, Method: miner.Methods.DeclareFaultsRecovered, Params: enc, - Value: types.NewInt(0), - From: minerInfo.Owner, // TODO: new miner... + Value: types.FromFil(30), // repay debt. + From: minerInfo.Owner, // TODO: new miner... } sm, err := client.MpoolPushMessage(ctx, msg, nil) require.NoError(t, err) @@ -857,50 +823,76 @@ func TestWindowPostDispute(t *testing.T, b APIBuilder, blocktime time.Duration) build.Clock.Sleep(blocktime) } - // And prove it. - { - fmt.Println("submitting good proof") - head, err := client.ChainHead(ctx) - require.NoError(t, err) + // Now try to be evil again + err = submitBadProof(ctx, client, evilMinerAddr, di, evilSectorLoc.Deadline, evilSectorLoc.Partition) + require.Error(t, err) + require.Contains(t, err.Error(), "message execution failed: exit 16, reason: window post failed: invalid PoSt") - commEpoch := di.Open - commRand, err := client.ChainGetRandomnessFromTickets( - ctx, head.Key(), crypto.DomainSeparationTag_PoStChainCommit, - commEpoch, nil, - ) - require.NoError(t, err) - params := &miner.SubmitWindowedPoStParams{ - ChainCommitEpoch: commEpoch, - ChainCommitRand: commRand, - Deadline: evilSectorLoc.Deadline, - Partitions: []miner.PoStPartition{{Index: evilSectorLoc.Partition}}, - Proofs: []proof3.PoStProof{{ - PoStProof: minerInfo.WindowPoStProofType, - ProofBytes: []byte("I'm soooo very evil."), - }}, - } + // It didn't work because we're recovering. +} - enc, aerr := actors.SerializeParams(params) - require.NoError(t, aerr) - - msg := &types.Message{ - To: evilMinerAddr, - Method: miner.Methods.SubmitWindowedPoSt, - Params: enc, - Value: types.NewInt(0), - From: minerInfo.Owner, - } - sm, err := client.MpoolPushMessage(ctx, msg, nil) - require.NoError(t, err) - - fmt.Println("waiting for evil proof") - rec, err := client.StateWaitMsg(ctx, sm.Cid(), build.MessageConfidence) - require.NoError(t, err) - require.Zero(t, rec.Receipt.ExitCode, "evil proof not accepted: %s", rec.Receipt.ExitCode.Error()) +func submitBadProof( + ctx context.Context, + client api.FullNode, maddr address.Address, + di *dline.Info, dlIdx, partIdx uint64, +) error { + head, err := client.ChainHead(ctx) + if err != nil { + return err } - // The power should be restored. - p, err = client.StateMinerPower(ctx, evilMinerAddr, types.EmptyTSK) - require.NoError(t, err) - require.Equal(t, p.MinerPower.RawBytePower, types.NewInt(uint64(ssz))) + from, err := client.WalletDefaultAddress(ctx) + if err != nil { + return err + } + + minerInfo, err := client.StateMinerInfo(ctx, maddr, head.Key()) + if err != nil { + return err + } + + commEpoch := di.Open + commRand, err := client.ChainGetRandomnessFromTickets( + ctx, head.Key(), crypto.DomainSeparationTag_PoStChainCommit, + commEpoch, nil, + ) + if err != nil { + return err + } + params := &miner.SubmitWindowedPoStParams{ + ChainCommitEpoch: commEpoch, + ChainCommitRand: commRand, + Deadline: dlIdx, + Partitions: []miner.PoStPartition{{Index: partIdx}}, + Proofs: []proof3.PoStProof{{ + PoStProof: minerInfo.WindowPoStProofType, + ProofBytes: []byte("I'm soooo very evil."), + }}, + } + + enc, aerr := actors.SerializeParams(params) + if aerr != nil { + return aerr + } + + msg := &types.Message{ + To: maddr, + Method: miner.Methods.SubmitWindowedPoSt, + Params: enc, + Value: types.NewInt(0), + From: from, + } + sm, err := client.MpoolPushMessage(ctx, msg, nil) + if err != nil { + return err + } + + rec, err := client.StateWaitMsg(ctx, sm.Cid(), build.MessageConfidence) + if err != nil { + return err + } + if rec.Receipt.ExitCode.IsError() { + return rec.Receipt.ExitCode + } + return nil } From db2a45d07af39af4fcc1cc89fbd58f777f8f3827 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 22 Jan 2021 09:41:21 -0800 Subject: [PATCH 55/58] fix test window post test name --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index b422a1146..c50b26173 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -595,7 +595,7 @@ workflows: test-suite-name: window-post - test-window-post-dispute: codecov-upload: true - go-test-flags: "-run=TestWindowedDispute" + go-test-flags: "-run=TestWindowPostDispute" winpost-test: "1" test-suite-name: window-post-dispute - test-terminate: From fdbb1d8f3bdd8b268ba20b3792516b51f3a9e86c Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 22 Jan 2021 10:04:06 -0800 Subject: [PATCH 56/58] tweak cc upgrade epoch --- api/test/ccupgrade.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/test/ccupgrade.go b/api/test/ccupgrade.go index 88d3e6ed7..606b9f22b 100644 --- a/api/test/ccupgrade.go +++ b/api/test/ccupgrade.go @@ -19,7 +19,7 @@ func TestCCUpgrade(t *testing.T, b APIBuilder, blocktime time.Duration) { for _, height := range []abi.ChainEpoch{ 2, // before 162, // while sealing - 520, // after upgrade deal + 530, // after upgrade deal 5000, // after } { height := height // make linters happy by copying From 94089a6a154a3c1afdd8d9c063efc403a1934be5 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 22 Jan 2021 11:15:43 -0800 Subject: [PATCH 57/58] remove todos --- api/test/window_post.go | 4 ++-- chain/actors/policy/policy.go | 5 +++-- go.mod | 2 +- go.sum | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/api/test/window_post.go b/api/test/window_post.go index 42ada189d..f8ab9412d 100644 --- a/api/test/window_post.go +++ b/api/test/window_post.go @@ -760,7 +760,7 @@ func TestWindowPostDispute(t *testing.T, b APIBuilder, blocktime time.Duration) Method: miner.Methods.DisputeWindowedPoSt, Params: enc, Value: types.NewInt(0), - From: defaultFrom, // TODO: new miner... + From: defaultFrom, } sm, err := client.MpoolPushMessage(ctx, msg, nil) require.NoError(t, err) @@ -803,7 +803,7 @@ func TestWindowPostDispute(t *testing.T, b APIBuilder, blocktime time.Duration) Method: miner.Methods.DeclareFaultsRecovered, Params: enc, Value: types.FromFil(30), // repay debt. - From: minerInfo.Owner, // TODO: new miner... + From: minerInfo.Owner, } sm, err := client.MpoolPushMessage(ctx, msg, nil) require.NoError(t, err) diff --git a/chain/actors/policy/policy.go b/chain/actors/policy/policy.go index 6086a8e40..e32b36743 100644 --- a/chain/actors/policy/policy.go +++ b/chain/actors/policy/policy.go @@ -38,7 +38,6 @@ func SetSupportedProofTypes(types ...abi.RegisteredSealProof) { miner2.PreCommitSealProofTypesV7 = make(map[abi.RegisteredSealProof]struct{}, len(types)*2) miner2.PreCommitSealProofTypesV8 = make(map[abi.RegisteredSealProof]struct{}, len(types)) - // TODO: need to remove the extra version specs actors. miner3.PreCommitSealProofTypesV0 = make(map[abi.RegisteredSealProof]struct{}, len(types)) miner3.PreCommitSealProofTypesV7 = make(map[abi.RegisteredSealProof]struct{}, len(types)*2) miner3.PreCommitSealProofTypesV8 = make(map[abi.RegisteredSealProof]struct{}, len(types)) @@ -146,9 +145,11 @@ func SetWPoStChallengeWindow(period abi.ChainEpoch) { miner2.WPoStChallengeWindow = period miner2.WPoStProvingPeriod = period * abi.ChainEpoch(miner2.WPoStPeriodDeadlines) - // TODO: change dispute window as well? This is only used for testing anyways. miner3.WPoStChallengeWindow = period miner3.WPoStProvingPeriod = period * abi.ChainEpoch(miner3.WPoStPeriodDeadlines) + // by default, this is 2x finality which is 30 periods. + // scale it if we're scaling the challenge period. + miner3.WPoStDisputeWindow = period * 30 } func GetWinningPoStSectorSetLookback(nwVer network.Version) abi.ChainEpoch { diff --git a/go.mod b/go.mod index abb4caa36..b4b43fb97 100644 --- a/go.mod +++ b/go.mod @@ -44,7 +44,7 @@ require ( github.com/filecoin-project/go-storedcounter v0.0.0-20200421200003-1c99c62e8a5b github.com/filecoin-project/specs-actors v0.9.13 github.com/filecoin-project/specs-actors/v2 v2.3.4 - github.com/filecoin-project/specs-actors/v3 v3.0.1-0.20210121225528-86a310df1e63 + github.com/filecoin-project/specs-actors/v3 v3.0.1-0.20210122191213-c7ea99141c44 github.com/filecoin-project/specs-storage v0.1.1-0.20201105051918-5188d9774506 github.com/filecoin-project/test-vectors/schema v0.0.5 github.com/gbrlsnchs/jwt/v3 v3.0.0-beta.1 diff --git a/go.sum b/go.sum index e992f4af2..6368b8bfb 100644 --- a/go.sum +++ b/go.sum @@ -307,8 +307,8 @@ github.com/filecoin-project/specs-actors/v2 v2.3.2 h1:2Vcf4CGa29kRh4JJ02m+FbvD/p github.com/filecoin-project/specs-actors/v2 v2.3.2/go.mod h1:UuJQLoTx/HPvvWeqlIFmC/ywlOLHNe8SNQ3OunFbu2Y= github.com/filecoin-project/specs-actors/v2 v2.3.4 h1:NZK2oMCcA71wNsUzDBmLQyRMzcCnX9tDGvwZ53G67j8= github.com/filecoin-project/specs-actors/v2 v2.3.4/go.mod h1:UuJQLoTx/HPvvWeqlIFmC/ywlOLHNe8SNQ3OunFbu2Y= -github.com/filecoin-project/specs-actors/v3 v3.0.1-0.20210121225528-86a310df1e63 h1:p7uz0gVvPktp//n6dW5Mx/a2zOGTLfA7LdqL6sAeJY8= -github.com/filecoin-project/specs-actors/v3 v3.0.1-0.20210121225528-86a310df1e63/go.mod h1:aVf248CfjfyCmVel4UuFAA3u+9UQjqtqHpgfYv+M+9U= +github.com/filecoin-project/specs-actors/v3 v3.0.1-0.20210122191213-c7ea99141c44 h1:QYCM/E0u5XJVJENnegPR7I7meciI3CITylc9BzyoiFE= +github.com/filecoin-project/specs-actors/v3 v3.0.1-0.20210122191213-c7ea99141c44/go.mod h1:aVf248CfjfyCmVel4UuFAA3u+9UQjqtqHpgfYv+M+9U= github.com/filecoin-project/specs-storage v0.1.1-0.20201105051918-5188d9774506 h1:Ur/l2+6qN+lQiqjozWWc5p9UDaAMDZKTlDS98oRnlIw= github.com/filecoin-project/specs-storage v0.1.1-0.20201105051918-5188d9774506/go.mod h1:nJRRM7Aa9XVvygr3W9k6xGF46RWzr2zxF/iGoAIfA/g= github.com/filecoin-project/test-vectors/schema v0.0.5 h1:w3zHQhzM4pYxJDl21avXjOKBLF8egrvwUwjpT8TquDg= From 0131b077bee6d0bd9eb3b101ed88cf0b082a2f4a Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 22 Jan 2021 11:19:37 -0800 Subject: [PATCH 58/58] re-enable watchdog --- node/modules/core.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/modules/core.go b/node/modules/core.go index aee6f2ea9..83a7e8d42 100644 --- a/node/modules/core.go +++ b/node/modules/core.go @@ -71,7 +71,7 @@ func MemoryConstraints() system.MemoryConstraints { // MemoryWatchdog starts the memory watchdog, applying the computed resource // constraints. func MemoryWatchdog(lr repo.LockedRepo, lc fx.Lifecycle, constraints system.MemoryConstraints) { - if true || os.Getenv(EnvWatchdogDisabled) == "1" { + if os.Getenv(EnvWatchdogDisabled) == "1" { log.Infof("memory watchdog is disabled via %s", EnvWatchdogDisabled) return }