diff --git a/app/submodule/chain/chain_submodule.go b/app/submodule/chain/chain_submodule.go index d28eb1cc5f..7d454ceb48 100644 --- a/app/submodule/chain/chain_submodule.go +++ b/app/submodule/chain/chain_submodule.go @@ -21,7 +21,6 @@ import ( "github.com/filecoin-project/venus/pkg/vmsupport" v0api "github.com/filecoin-project/venus/venus-shared/api/chain/v0" v1api "github.com/filecoin-project/venus/venus-shared/api/chain/v1" - "github.com/filecoin-project/venus/venus-shared/types" ) // ChainSubmodule enhances the `Node` with chain capabilities. @@ -33,8 +32,7 @@ type ChainSubmodule struct { //nolint SystemCall vm.SyscallsImpl CirculatingSupplyCalculator *chain.CirculatingSupplyCalculator - CheckPoint types.TipSetKey - Drand beacon.Schedule + Drand beacon.Schedule config chainConfig @@ -92,7 +90,6 @@ func NewChainSubmodule(ctx context.Context, Drand: drand, config: config, Waiter: waiter, - CheckPoint: chainStore.GetCheckPoint(), } err = store.ChainReader.Load(context.TODO()) if err != nil { diff --git a/app/submodule/chain/chaininfo_api.go b/app/submodule/chain/chaininfo_api.go index b2fc4acbbb..186e8e7907 100644 --- a/app/submodule/chain/chaininfo_api.go +++ b/app/submodule/chain/chaininfo_api.go @@ -761,6 +761,7 @@ func (cia *chainInfoAPI) StateGetNetworkParams(ctx context.Context) (*types.Netw UpgradePhoenixHeight: cfg.NetworkParams.ForkUpgradeParam.UpgradePhoenixHeight, UpgradeWaffleHeight: cfg.NetworkParams.ForkUpgradeParam.UpgradeWaffleHeight, UpgradeTuktukHeight: cfg.NetworkParams.ForkUpgradeParam.UpgradeTuktukHeight, + UpgradeTeepHeight: cfg.NetworkParams.ForkUpgradeParam.UpgradeTeepHeight, }, Eip155ChainID: cfg.NetworkParams.Eip155ChainID, } @@ -942,3 +943,22 @@ func (cia *chainInfoAPI) StateCompute(ctx context.Context, height abi.ChainEpoch Trace: t, }, nil } + +func (cia *chainInfoAPI) StateMarketProposalPending(ctx context.Context, proposalCid cid.Cid, tsk types.TipSetKey) (bool, error) { + ts, err := cia.ChainGetTipSet(ctx, tsk) + if err != nil { + return false, fmt.Errorf("loading tipset %s: %w", tsk, err) + } + + st, err := cia.chain.Stmgr.GetMarketState(ctx, ts) + if err != nil { + return false, err + } + + props, err := st.PendingProposals() + if err != nil { + return false, err + } + + return props.Has(proposalCid) +} diff --git a/app/submodule/chain/miner_api.go b/app/submodule/chain/miner_api.go index 5cd3127376..b72e12306e 100644 --- a/app/submodule/chain/miner_api.go +++ b/app/submodule/chain/miner_api.go @@ -730,12 +730,12 @@ func (msa *minerStateAPI) calculateSectorWeight(ctx context.Context, maddr addre return types.EmptyInt, fmt.Errorf("market actor not found") } else if s, err := market.Load(store, act); err != nil { return types.EmptyInt, fmt.Errorf("loading market actor state: %w", err) - } else if w, vw, err := s.VerifyDealsForActivation(maddr, pci.DealIDs, height, pci.Expiration); err != nil { + } else if vw, err := s.VerifyDealsForActivation(maddr, pci.DealIDs, height, pci.Expiration); err != nil { return types.EmptyInt, fmt.Errorf("verifying deals for activation: %w", err) } else { // NB: not exactly accurate, but should always lead us to *over* estimate, not under duration := pci.Expiration - height - sectorWeight = builtin.QAPowerForWeight(ssize, duration, w, vw) + sectorWeight = builtin.QAPowerForWeight(ssize, duration, vw) } return sectorWeight, nil @@ -937,7 +937,7 @@ func (msa *minerStateAPI) StateMinerInitialPledgeForSector(ctx context.Context, } verifiedWeight := big.Mul(big.NewIntUnsigned(verifiedSize), big.NewInt(int64(sectorDuration))) - sectorWeight := builtin.QAPowerForWeight(sectorSize, sectorDuration, big.Zero(), verifiedWeight) + sectorWeight := builtin.QAPowerForWeight(sectorSize, sectorDuration, verifiedWeight) epochsSinceRampStart, rampDurationEpochs, err := msa.getPledgeRampParams(ctx, ts.Height(), state) if err != nil { diff --git a/app/submodule/eth/eth_api.go b/app/submodule/eth/eth_api.go index d5d89ff144..151b558adc 100644 --- a/app/submodule/eth/eth_api.go +++ b/app/submodule/eth/eth_api.go @@ -1436,6 +1436,9 @@ func (a *ethAPI) EthTraceFilter(ctx context.Context, filter types.EthTraceFilter for blkNum := fromBlock; blkNum <= toBlock; blkNum++ { blockTraces, err := a.EthTraceBlock(ctx, strconv.FormatUint(uint64(blkNum), 10)) if err != nil { + if errors.Is(err, &types.ErrNullRound{}) { + continue + } return nil, fmt.Errorf("cannot get trace for block %d: %w", blkNum, err) } diff --git a/app/submodule/eth/eth_trace.go b/app/submodule/eth/eth_trace.go index 9b1c926b22..b01391ea08 100644 --- a/app/submodule/eth/eth_trace.go +++ b/app/submodule/eth/eth_trace.go @@ -444,11 +444,14 @@ func decodeCreateViaEAM(et *types.ExecutionTrace) (initcode []byte, addr *types. default: return nil, nil, fmt.Errorf("unexpected CREATE method %d", et.Msg.Method) } - ret, err := decodeReturn[eam12.CreateReturn](&et.MsgRct) - if err != nil { - return nil, nil, err + if et.MsgRct.ExitCode.IsSuccess() { + ret, err := decodeReturn[eam12.CreateReturn](&et.MsgRct) + if err != nil { + return nil, nil, fmt.Errorf("failed to decode EAM create return: %w", err) + } + addr = (*types.EthAddress)(&ret.EthAddress) } - return initcode, (*types.EthAddress)(&ret.EthAddress), nil + return initcode, addr, nil } // Build an EthTrace for an EVM "create" operation. This should only be called with an diff --git a/extern/filecoin-ffi b/extern/filecoin-ffi index 62131ac060..72e100df9d 160000 --- a/extern/filecoin-ffi +++ b/extern/filecoin-ffi @@ -1 +1 @@ -Subproject commit 62131ac060d4d0cb8f963c1de5b291fba704079c +Subproject commit 72e100df9db736aeda690672ab120500ddbd5e0d diff --git a/fixtures/networks/butterfly.go b/fixtures/networks/butterfly.go index 33495955ce..6ca2f12435 100644 --- a/fixtures/networks/butterfly.go +++ b/fixtures/networks/butterfly.go @@ -21,7 +21,7 @@ func ButterflySnapNet() *NetworkConf { Network: config.NetworkParamsConfig{ DevNet: true, NetworkType: types.NetworkButterfly, - GenesisNetworkVersion: network.Version22, + GenesisNetworkVersion: network.Version24, ReplaceProofTypes: []abi.RegisteredSealProof{ abi.RegisteredSealProof_StackedDrg512MiBV1, abi.RegisteredSealProof_StackedDrg32GiBV1, @@ -63,8 +63,9 @@ func ButterflySnapNet() *NetworkConf { UpgradeCalibrationDragonFixHeight: -102, // This fix upgrade only ran on calibrationnet UpgradePhoenixHeight: -26, UpgradeWaffleHeight: -27, - UpgradeTuktukHeight: 9999999, + UpgradeTuktukHeight: -28, UpgradeTuktukPowerRampDurationEpochs: builtin.EpochsInYear, + UpgradeTeepHeight: 100, }, DrandSchedule: map[abi.ChainEpoch]config.DrandEnum{0: config.DrandQuicknet}, AddressNetwork: address.Testnet, diff --git a/fixtures/networks/calibration.go b/fixtures/networks/calibration.go index 988c80afbd..8ace31f255 100644 --- a/fixtures/networks/calibration.go +++ b/fixtures/networks/calibration.go @@ -73,6 +73,7 @@ func Calibration() *NetworkConf { UpgradeWaffleHeight: 1779094, // 2024-07-11T12:00:00Z UpgradeTuktukHeight: 2078794, // 2024-10-23T13:30:00Z UpgradeTuktukPowerRampDurationEpochs: builtin.EpochsInDay * 3, + UpgradeTeepHeight: 2235454, // 2024-12-16T23:00:00Z }, DrandSchedule: map[abi.ChainEpoch]config.DrandEnum{0: 1}, AddressNetwork: address.Testnet, diff --git a/fixtures/networks/forcenet.go b/fixtures/networks/forcenet.go index 0330cc1550..524a1013c0 100644 --- a/fixtures/networks/forcenet.go +++ b/fixtures/networks/forcenet.go @@ -19,7 +19,7 @@ func ForceNet() *NetworkConf { Network: config.NetworkParamsConfig{ DevNet: true, NetworkType: types.NetworkForce, - GenesisNetworkVersion: network.Version23, + GenesisNetworkVersion: network.Version24, ReplaceProofTypes: []abi.RegisteredSealProof{ abi.RegisteredSealProof_StackedDrg8MiBV1, abi.RegisteredSealProof_StackedDrg512MiBV1, @@ -65,8 +65,9 @@ func ForceNet() *NetworkConf { UpgradeCalibrationDragonFixHeight: -102, // This fix upgrade only ran on calibrationnet UpgradePhoenixHeight: -26, UpgradeWaffleHeight: -27, - UpgradeTuktukHeight: 200, + UpgradeTuktukHeight: -28, UpgradeTuktukPowerRampDurationEpochs: 200, + UpgradeTeepHeight: 200, }, DrandSchedule: map[abi.ChainEpoch]config.DrandEnum{0: config.DrandQuicknet}, AddressNetwork: address.Testnet, diff --git a/fixtures/networks/integrationtestnet.go b/fixtures/networks/integrationtestnet.go index a0fc6ae0fb..c746efc5ed 100644 --- a/fixtures/networks/integrationtestnet.go +++ b/fixtures/networks/integrationtestnet.go @@ -58,6 +58,7 @@ func IntegrationNet() *NetworkConf { UpgradeCalibrationDragonFixHeight: -102, // This fix upgrade only ran on calibrationnet UpgradeWaffleHeight: 4154640, UpgradeTuktukHeight: 4461240, + UpgradeTeepHeight: 99999999, }, DrandSchedule: map[abi.ChainEpoch]config.DrandEnum{0: 5, 51000: 1}, AddressNetwork: address.Testnet, diff --git a/fixtures/networks/interopnet.go b/fixtures/networks/interopnet.go index f1fc6efab4..5195e86f50 100644 --- a/fixtures/networks/interopnet.go +++ b/fixtures/networks/interopnet.go @@ -64,8 +64,9 @@ func InteropNet() *NetworkConf { UpgradeCalibrationDragonFixHeight: -102, // This fix upgrade only ran on calibrationnet UpgradePhoenixHeight: -26, UpgradeWaffleHeight: -27, - UpgradeTuktukHeight: 50, + UpgradeTuktukHeight: -28, UpgradeTuktukPowerRampDurationEpochs: builtin.EpochsInYear, + UpgradeTeepHeight: 50, }, DrandSchedule: map[abi.ChainEpoch]config.DrandEnum{0: config.DrandQuicknet}, AddressNetwork: address.Testnet, diff --git a/fixtures/networks/mainnet.go b/fixtures/networks/mainnet.go index aff7b34311..3eef0987df 100644 --- a/fixtures/networks/mainnet.go +++ b/fixtures/networks/mainnet.go @@ -70,6 +70,7 @@ func Mainnet() *NetworkConf { UpgradeWaffleHeight: 4154640, // 2024-08-06T12:00:00Z UpgradeTuktukHeight: 4461240, // 2024-11-20T23:00:00Z UpgradeTuktukPowerRampDurationEpochs: builtin2.EpochsInYear, + UpgradeTeepHeight: 99999999999, }, DrandSchedule: map[abi.ChainEpoch]config.DrandEnum{0: 5, 51000: 1}, AddressNetwork: address.Mainnet, diff --git a/fixtures/networks/net_2k.go b/fixtures/networks/net_2k.go index 11573296ea..691056cb42 100644 --- a/fixtures/networks/net_2k.go +++ b/fixtures/networks/net_2k.go @@ -18,7 +18,7 @@ func Net2k() *NetworkConf { Network: config.NetworkParamsConfig{ DevNet: true, NetworkType: types.Network2k, - GenesisNetworkVersion: network.Version23, + GenesisNetworkVersion: network.Version24, ReplaceProofTypes: []abi.RegisteredSealProof{ abi.RegisteredSealProof_StackedDrg2KiBV1, abi.RegisteredSealProof_StackedDrg8MiBV1, @@ -60,7 +60,8 @@ func Net2k() *NetworkConf { UpgradePhoenixHeight: -26, UpgradeWaffleHeight: -27, UpgradeTuktukPowerRampDurationEpochs: 200, - UpgradeTuktukHeight: 200, + UpgradeTuktukHeight: -28, + UpgradeTeepHeight: 200, }, DrandSchedule: map[abi.ChainEpoch]config.DrandEnum{0: config.DrandQuicknet}, AddressNetwork: address.Testnet, diff --git a/go.mod b/go.mod index d61e0e4a7c..cb32a1ce57 100644 --- a/go.mod +++ b/go.mod @@ -32,7 +32,7 @@ require ( github.com/filecoin-project/go-fil-markets v1.28.2 github.com/filecoin-project/go-jsonrpc v0.1.5 github.com/filecoin-project/go-paramfetch v0.0.4 - github.com/filecoin-project/go-state-types v0.15.0 + github.com/filecoin-project/go-state-types v0.16.0-rc1 github.com/filecoin-project/pubsub v1.0.0 github.com/filecoin-project/specs-actors v0.9.15-0.20220514164640-94e0d5e123bd github.com/filecoin-project/specs-actors/v2 v2.3.6 @@ -92,7 +92,7 @@ require ( github.com/prometheus/client_golang v1.19.1 github.com/raulk/clock v1.1.0 github.com/streadway/handy v0.0.0-20200128134331-0f66f006fb2e - github.com/stretchr/testify v1.9.0 + github.com/stretchr/testify v1.10.0 github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 github.com/whyrusleeping/cbor-gen v0.2.0 github.com/whyrusleeping/go-sysinfo v0.0.0-20190219211824-4a357d4b90b1 @@ -103,11 +103,11 @@ require ( go.opentelemetry.io/otel/exporters/prometheus v0.50.0 go.opentelemetry.io/otel/sdk v1.28.0 go.uber.org/zap v1.27.0 - golang.org/x/crypto v0.28.0 + golang.org/x/crypto v0.29.0 golang.org/x/net v0.29.0 golang.org/x/oauth2 v0.21.0 - golang.org/x/sync v0.8.0 - golang.org/x/sys v0.26.0 + golang.org/x/sync v0.9.0 + golang.org/x/sys v0.27.0 golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da gopkg.in/cheggaaa/pb.v1 v1.0.28 gorm.io/driver/mysql v1.1.1 @@ -342,8 +342,8 @@ require ( golang.org/x/arch v0.3.0 // indirect golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e // indirect golang.org/x/mod v0.20.0 // indirect - golang.org/x/term v0.25.0 // indirect - golang.org/x/text v0.19.0 // indirect + golang.org/x/term v0.26.0 // indirect + golang.org/x/text v0.20.0 // indirect golang.org/x/time v0.6.0 // indirect golang.org/x/tools v0.24.0 // indirect google.golang.org/api v0.81.0 // indirect diff --git a/go.sum b/go.sum index 61b0c5cc72..eafe8a8422 100644 --- a/go.sum +++ b/go.sum @@ -323,8 +323,9 @@ github.com/filecoin-project/go-state-types v0.1.4/go.mod h1:xCA/WfKlC2zcn3fUmDv4 github.com/filecoin-project/go-state-types v0.1.6/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q= github.com/filecoin-project/go-state-types v0.1.10/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q= github.com/filecoin-project/go-state-types v0.14.0/go.mod h1:cDbxwjbmVtV+uNi5D/cFtxKlsRqibnQNlz7xQA1EqYg= -github.com/filecoin-project/go-state-types v0.15.0 h1:GaUSCti0tGMzLg7fVpRjtNVGBvirbMFzLfyWbR+qzWE= github.com/filecoin-project/go-state-types v0.15.0/go.mod h1:2okQFn4DVOt5Bs6OFh0lLSzn8p7Vczh8XjgaKLKhKgI= +github.com/filecoin-project/go-state-types v0.16.0-rc1 h1:/51MhupBAjfmWygUKDZCdLOzAnKFcayPHX9ApTswgmo= +github.com/filecoin-project/go-state-types v0.16.0-rc1/go.mod h1:4rjTgHP6LWrkQXQCgx+dRGDa0gnk4WiJVCFwZtuDOGE= github.com/filecoin-project/go-statemachine v0.0.0-20200925024713-05bd7c71fbfe/go.mod h1:FGwQgZAt2Gh5mjlwJUlVB62JeYdo+if0xWxSEfBD9ig= github.com/filecoin-project/go-statemachine v1.0.3 h1:N07o6alys+V1tNoSTi4WuuoeNC4erS/6jE74+NsgQuk= github.com/filecoin-project/go-statemachine v1.0.3/go.mod h1:jZdXXiHa61n4NmgWFG4w8tnqgvZVHYbJ3yW7+y8bF54= @@ -1369,8 +1370,9 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/stvp/go-udp-testing v0.0.0-20201019212854-469649b16807/go.mod h1:7jxmlfBCDBXRzr0eAQJ48XC1hBu1np4CS5+cHEYfwpc= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/subosito/gotenv v1.4.0 h1:yAzM1+SmVcz5R4tXGsNMu1jUl2aOJXoiWUCEwwnGrvs= @@ -1587,8 +1589,9 @@ golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOM golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M= golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= -golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw= golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U= +golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ= +golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -1750,8 +1753,9 @@ golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ= +golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180202135801-37707fdb30a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180810173357-98c5dad5d1a0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -1875,8 +1879,9 @@ golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s= +golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -1895,8 +1900,9 @@ golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58= golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4= golang.org/x/term v0.23.0/go.mod h1:DgV24QBUrK6jhZXl+20l6UWznPlwAHm1Q1mGHtydmSk= -golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24= golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M= +golang.org/x/term v0.26.0 h1:WEQa6V3Gja/BhNxg540hBip/kkaYtRg3cxg4oXSw4AU= +golang.org/x/term v0.26.0/go.mod h1:Si5m1o57C5nBNQo5z1iq+XDijt21BDBDp2bK0QI8e3E= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -1916,8 +1922,9 @@ golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= -golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug= +golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= diff --git a/pkg/chain/store.go b/pkg/chain/store.go index 55620b1f4d..4f34553c9e 100644 --- a/pkg/chain/store.go +++ b/pkg/chain/store.go @@ -100,7 +100,7 @@ type Store struct { // head is the tipset at the head of the best known chain. head *types.TipSet - checkPoint types.TipSetKey + checkPoint *types.TipSet // Protects head and genesisCid. mu sync.RWMutex @@ -143,7 +143,6 @@ func NewStore(chainDs repo.Datastore, bsstore: bsstore, headEvents: pubsub.New(64), - checkPoint: types.EmptyTSK, genesis: genesisCid, reorgNotifeeCh: make(chan ReorgNotifee), tsCache: tsCache, @@ -156,11 +155,22 @@ func NewStore(chainDs repo.Datastore, val, err := store.ds.Get(context.TODO(), CheckPoint) if err != nil { - store.checkPoint = types.NewTipSetKey(genesisCid) + store.checkPoint, err = store.GetTipSet(context.TODO(), types.NewTipSetKey(genesisCid)) + if err != nil { + panic(fmt.Errorf("cannot get genesis tipset: %w", err)) + } } else { - _ = store.checkPoint.UnmarshalCBOR(bytes.NewReader(val)) //nolint:staticcheck + var checkPointTSK types.TipSetKey + err := checkPointTSK.UnmarshalCBOR(bytes.NewReader(val)) + if err != nil { + panic(fmt.Errorf("cannot unmarshal checkpoint %s: %w", string(val), err)) + } + store.checkPoint, err = store.GetTipSet(context.TODO(), checkPointTSK) + if err != nil { + panic(fmt.Errorf("cannot get checkpoint tipset: %w", err)) + } } - log.Infof("check point value: %v", store.checkPoint) + log.Infof("load check point height: %d, key: %v", store.checkPoint.Height(), store.checkPoint.Key()) store.reorgCh = store.reorgWorker(context.TODO()) return store @@ -1112,8 +1122,8 @@ func (store *Store) SetCheckpoint(ctx context.Context, ts *types.TipSet) error { return err } - store.mu.RLock() - defer store.mu.RUnlock() + store.mu.Lock() + defer store.mu.Unlock() finality := store.head.Height() - policy.ChainFinality targetChain, currentChain := ts, store.head @@ -1167,7 +1177,7 @@ func (store *Store) SetCheckpoint(ctx context.Context, ts *types.TipSet) error { if err := store.ds.Put(ctx, CheckPoint, buf.Bytes()); err != nil { return fmt.Errorf("checkpoint failed: failed to record checkpoint in the datastore: %w", err) } - store.checkPoint = ts.Key() + store.checkPoint = ts return nil } @@ -1187,7 +1197,7 @@ func (store *Store) IsAncestorOf(ctx context.Context, a, b *types.TipSet) (bool, } // GetCheckPoint get the check point from store or disk. -func (store *Store) GetCheckPoint() types.TipSetKey { +func (store *Store) GetCheckPoint() *types.TipSet { store.mu.RLock() defer store.mu.RUnlock() @@ -1722,7 +1732,7 @@ func (store *Store) exceedsForkLength(ctx context.Context, synced, external *typ } // Now check to see if we've walked back to the checkpoint. - if synced.Key().Equals(store.checkPoint) { + if synced.Key().Equals(store.checkPoint.Key()) { return true, nil } diff --git a/pkg/chain/store_test.go b/pkg/chain/store_test.go index 15fab6420e..c82e63cf4c 100644 --- a/pkg/chain/store_test.go +++ b/pkg/chain/store_test.go @@ -43,6 +43,8 @@ func (cbor *CborBlockStore) PutBlocks(ctx context.Context, blocks []*types.Block func newChainStore(r repo.Repo, genTS *types.TipSet) *CborBlockStore { tempBlock := r.Datastore() cborStore := cbor.NewCborStore(tempBlock) + blkBytes, _ := genTS.Blocks()[0].ToStorageBlock() + _ = tempBlock.Put(context.Background(), blkBytes) return &CborBlockStore{ Store: chain.NewStore(r.ChainDatastore(), tempBlock, genTS.At(0).Cid(), chainselector.Weight), cborStore: cborStore, diff --git a/pkg/chainsync/syncer/syncer.go b/pkg/chainsync/syncer/syncer.go index ced8977138..3c1b756561 100644 --- a/pkg/chainsync/syncer/syncer.go +++ b/pkg/chainsync/syncer/syncer.go @@ -60,6 +60,7 @@ var ( ErrNewChainTooLong = errors.New("input chain forked from best chain past finality limit") // ErrUnexpectedStoreState indicates that the syncer's chain bsstore is violating expected invariants. ErrUnexpectedStoreState = errors.New("the chain bsstore is in an unexpected state") + ErrForkCheckpoint = fmt.Errorf("fork would require us to diverge from checkpointed block") logSyncer = logging.Logger("chainsync.syncer") ) @@ -137,8 +138,7 @@ type Syncer struct { clock clock.Clock - bsstore blockstoreutil.Blockstore - checkPoint types.TipSetKey + bsstore blockstoreutil.Blockstore fork fork.IFork @@ -199,45 +199,41 @@ func (syncer *Syncer) syncOne(ctx context.Context, parent, next *types.TipSet) e stopwatch := syncOneTimer.Start() defer stopwatch(ctx) - var err error - - if !parent.Key().Equals(syncer.checkPoint) { - var wg errgroup.Group - for i := 0; i < next.Len(); i++ { - blk := next.At(i) - wg.Go(func() error { - // Fetch the URL. - err := syncer.blockValidator.ValidateFullBlock(ctx, blk) - if err == nil { - if err := syncer.chainStore.AddToTipSetTracker(ctx, blk); err != nil { - return fmt.Errorf("failed to add validated header to tipset tracker: %w", err) - } + var wg errgroup.Group + for i := 0; i < next.Len(); i++ { + blk := next.At(i) + wg.Go(func() error { + // Fetch the URL. + err := syncer.blockValidator.ValidateFullBlock(ctx, blk) + if err == nil { + if err := syncer.chainStore.AddToTipSetTracker(ctx, blk); err != nil { + return fmt.Errorf("failed to add validated header to tipset tracker: %w", err) } - return err - }) - } - err = wg.Wait() - if err != nil { - var rootNotMatch bool // nolint - - if merr, isok := err.(*multierror.Error); isok { - for _, e := range merr.Errors { - if isRootNotMatch(e) { - rootNotMatch = true - break - } - } - } else { - rootNotMatch = isRootNotMatch(err) // nolint } + return err + }) + } + err := wg.Wait() + if err != nil { + var rootNotMatch bool // nolint - if rootNotMatch { // nolint - // todo: should here rollback, and re-compute? - _ = syncer.stmgr.Rollback(ctx, parent, next) + if merr, isok := err.(*multierror.Error); isok { + for _, e := range merr.Errors { + if isRootNotMatch(e) { + rootNotMatch = true + break + } } + } else { + rootNotMatch = isRootNotMatch(err) // nolint + } - return fmt.Errorf("validate mining failed %w", err) + if rootNotMatch { // nolint + // todo: should here rollback, and re-compute? + _ = syncer.stmgr.Rollback(ctx, parent, next) } + + return fmt.Errorf("validate mining failed %w", err) } syncer.chainStore.PersistTipSetKey(ctx, next.Key()) @@ -297,8 +293,25 @@ func (syncer *Syncer) HandleNewTipSet(ctx context.Context, target *syncTypes.Tar return errors.New("do not sync to a target has synced before") } + if target.Head.Height() == head.Height() { + // check if maybeHead is fully contained in headTipSet + // meaning we already synced all the blocks that are a part of maybeHead + // if that is the case, there is nothing for us to do + // we need to exit out early, otherwise checkpoint-fork logic might wrongly reject it + fullyContained := true + for _, c := range target.Head.Cids() { + if !head.Contains(c) { + fullyContained = false + break + } + } + if fullyContained { + return nil + } + } + syncer.exchangeClient.AddPeer(target.Sender) - tipsets, err := syncer.fetchChainBlocks(ctx, head, target.Head) + tipsets, err := syncer.fetchChainBlocks(ctx, head, target.Head, false) if err != nil { return errors.Wrapf(err, "failure fetching or validating headers") } @@ -346,7 +359,7 @@ func (syncer *Syncer) syncSegement(ctx context.Context, target *syncTypes.Target errProcessChan <- processErr return } - if !parent.Key().Equals(syncer.checkPoint) { + if !parent.Key().Equals(syncer.chainStore.GetCheckPoint().Key()) { logSyncer.Debugf("set chain head, height:%d, blocks:%d", parent.Height(), parent.Len()) if err := syncer.chainStore.RefreshHeaviestTipSet(ctx, parent.Height()); err != nil { errProcessChan <- err @@ -374,7 +387,7 @@ func (syncer *Syncer) syncSegement(ctx context.Context, target *syncTypes.Target // if local db not exist, get block from network(libp2p), // if there is a fork, get the common root tipset of knowntip and targettip, and return the block data from root tipset to targettip // local(···->A->B) + incoming(C->D->E) => ···->A->B->C->D->E -func (syncer *Syncer) fetchChainBlocks(ctx context.Context, knownTip *types.TipSet, targetTip *types.TipSet) ([]*types.TipSet, error) { +func (syncer *Syncer) fetchChainBlocks(ctx context.Context, knownTip *types.TipSet, targetTip *types.TipSet, ignoreCheckpoint bool) ([]*types.TipSet, error) { chainTipsets := []*types.TipSet{targetTip} flushDB := func(saveTips []*types.TipSet) error { bs := blockstoreutil.NewTemporary() @@ -448,6 +461,13 @@ loop: if err != nil { return nil, fmt.Errorf("failed to load next local tipset: %w", err) } + + if !ignoreCheckpoint { + if chkpt := syncer.chainStore.GetCheckPoint(); chkpt != nil && base.Height() <= chkpt.Height() { + return nil, fmt.Errorf("merge point affecting the checkpoing: %w", ErrForkCheckpoint) + } + } + if base.IsChildOf(knownParent) { // common case: receiving a block thats potentially part of the same tipset as our best block chain.Reverse(chainTipsets) @@ -456,7 +476,7 @@ loop: logSyncer.Warnf("(fork detected) synced header chain, base: %v(%d), knownTip: %v(%d)", base.Key(), base.Height(), knownTip.Key(), knownTip.Height()) - fork, err := syncer.syncFork(ctx, base, knownTip) + fork, err := syncer.syncFork(ctx, base, knownTip, ignoreCheckpoint) if err != nil { if errors.Is(err, ErrForkTooLong) { // TODO: we're marking this block bad in the same way that we mark invalid blocks bad. Maybe distinguish? @@ -486,7 +506,15 @@ loop: // D->E-F(targetTip) // A => D->E>F // B-C(knownTip) -func (syncer *Syncer) syncFork(ctx context.Context, incoming *types.TipSet, known *types.TipSet) ([]*types.TipSet, error) { +func (syncer *Syncer) syncFork(ctx context.Context, incoming *types.TipSet, known *types.TipSet, ignoreCheckpoint bool) ([]*types.TipSet, error) { + var chkpt *types.TipSet + if !ignoreCheckpoint { + chkpt = syncer.chainStore.GetCheckPoint() + if known.Equals(chkpt) { + return nil, ErrForkCheckpoint + } + } + incomingParentsTsk := incoming.Parents() commonParent := false for _, incomingParent := range incomingParentsTsk.Cids() { @@ -701,7 +729,7 @@ func (syncer *Syncer) SyncCheckpoint(ctx context.Context, tsk types.TipSetKey) e if anc, err := syncer.chainStore.IsAncestorOf(ctx, ts, head); err != nil { return fmt.Errorf("failed to walk the chain when checkpointing: %w", err) } else if !anc { - tipsets, err := syncer.fetchChainBlocks(ctx, head, target.Head) + tipsets, err := syncer.fetchChainBlocks(ctx, head, target.Head, true) if err != nil { return errors.Wrapf(err, "failure fetching or validating headers") } diff --git a/pkg/config/config.go b/pkg/config/config.go index 379baccf46..912cdf10e7 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -351,6 +351,7 @@ type ForkUpgradeConfig struct { UpgradeWaffleHeight abi.ChainEpoch `json:"upgradeWaffleHeight"` UpgradeTuktukHeight abi.ChainEpoch `json:"upgradeTuktukHeight"` UpgradeTuktukPowerRampDurationEpochs abi.ChainEpoch `json:"upgradeTuktukPowerRampDurationEpochs"` + UpgradeTeepHeight abi.ChainEpoch `json:"upgradeTeepHeight"` } func IsNearUpgrade(epoch, upgradeEpoch abi.ChainEpoch) bool { @@ -394,6 +395,7 @@ var DefaultForkUpgradeParam = &ForkUpgradeConfig{ UpgradeWaffleHeight: 4154640, UpgradeTuktukHeight: 4461240, UpgradeTuktukPowerRampDurationEpochs: 200, + UpgradeTeepHeight: 9999999999, } func newDefaultNetworkParamsConfig() *NetworkParamsConfig { diff --git a/pkg/constants/shared_vals.go b/pkg/constants/shared_vals.go index e64bf58f3b..7c20995522 100644 --- a/pkg/constants/shared_vals.go +++ b/pkg/constants/shared_vals.go @@ -16,7 +16,7 @@ const TestNetworkVersion = network.Version{{.latestNetworkVersion}} /* inline-gen start */ -const TestNetworkVersion = network.Version24 +const TestNetworkVersion = network.Version25 /* inline-gen end */ diff --git a/pkg/fork/fork.go b/pkg/fork/fork.go index d41e45713e..fc3d92c632 100644 --- a/pkg/fork/fork.go +++ b/pkg/fork/fork.go @@ -41,6 +41,7 @@ import ( nv22 "github.com/filecoin-project/go-state-types/builtin/v13/migration" nv23 "github.com/filecoin-project/go-state-types/builtin/v14/migration" nv24 "github.com/filecoin-project/go-state-types/builtin/v15/migration" + nv25 "github.com/filecoin-project/go-state-types/builtin/v16/migration" nv17 "github.com/filecoin-project/go-state-types/builtin/v9/migration" "github.com/filecoin-project/go-state-types/migration" "github.com/filecoin-project/specs-actors/actors/migration/nv3" @@ -458,6 +459,18 @@ func DefaultUpgradeSchedule(cf *ChainFork, upgradeHeight *config.ForkUpgradeConf }}, Expensive: true, }, + { + Height: upgradeHeight.UpgradeTeepHeight, + Network: network.Version25, + Migration: cf.UpgradeActorsV16, + PreMigrations: []PreMigration{{ + PreMigration: cf.PreUpgradeActorsV16, + StartWithin: 120, + DontStartWithin: 15, + StopWithin: 10, + }}, + Expensive: true, + }, } for _, u := range updates { @@ -3586,6 +3599,115 @@ func (c *ChainFork) upgradeActorsV15Common( return newRoot, nil } +func (c *ChainFork) PreUpgradeActorsV16(ctx context.Context, cache MigrationCache, root cid.Cid, epoch abi.ChainEpoch, ts *types.TipSet) error { + // Use half the CPUs for pre-migration, but leave at least 3. + workerCount := MigrationMaxWorkerCount + if workerCount <= 4 { + workerCount = 1 + } else { + workerCount /= 2 + } + + nv := c.GetNetworkVersion(ctx, epoch) + _, lbRoot, err := c.cr.GetLookbackTipSetForRound(ctx, ts, epoch, nv) + if err != nil { + return fmt.Errorf("error getting lookback ts for premigration: %w", err) + } + + config := migration.Config{ + MaxWorkers: uint(workerCount), + ProgressLogPeriod: time.Minute * 5, + } + + _, err = c.upgradeActorsV16Common(ctx, cache, lbRoot, epoch, config) + return err +} + +func (c *ChainFork) UpgradeActorsV16(ctx context.Context, + cache MigrationCache, + root cid.Cid, + epoch abi.ChainEpoch, + ts *types.TipSet, +) (cid.Cid, error) { + // Use all the CPUs except 2. + workerCount := MigrationMaxWorkerCount - 3 + if workerCount <= 0 { + workerCount = 1 + } + config := migration.Config{ + MaxWorkers: uint(workerCount), + JobQueueSize: 1000, + ResultQueueSize: 100, + ProgressLogPeriod: 10 * time.Second, + } + newRoot, err := c.upgradeActorsV16Common(ctx, cache, root, epoch, config) + if err != nil { + return cid.Undef, fmt.Errorf("migrating actors vXX state: %w", err) + } + return newRoot, nil +} + +func (c *ChainFork) upgradeActorsV16Common( + ctx context.Context, + cache MigrationCache, + root cid.Cid, + epoch abi.ChainEpoch, + config migration.Config, +) (cid.Cid, error) { + writeStore := blockstoreutil.NewAutobatch(ctx, c.bs, units.GiB/4) + adtStore := adt.WrapStore(ctx, cbor.NewCborStore(writeStore)) + // ensure that the manifest is loaded in the blockstore + if err := actors.LoadBundles(ctx, writeStore, actorstypes.Version16); err != nil { + return cid.Undef, fmt.Errorf("failed to load manifest bundle: %w", err) + } + + // Load the state root. + var stateRoot vmstate.StateRoot + if err := adtStore.Get(ctx, root, &stateRoot); err != nil { + return cid.Undef, fmt.Errorf("failed to decode state root: %w", err) + } + + if stateRoot.Version != vmstate.StateTreeVersion5 { + return cid.Undef, fmt.Errorf( + "expected state root version 5 for actors v16 upgrade, got %d", + stateRoot.Version, + ) + } + + manifest, ok := actors.GetManifest(actorstypes.Version16) + if !ok { + return cid.Undef, fmt.Errorf("no manifest CID for v16 upgrade") + } + + // Perform the migration + newHamtRoot, err := nv25.MigrateStateTree(ctx, adtStore, manifest, stateRoot.Actors, epoch, config, + migrationLogger{}, cache) + if err != nil { + return cid.Undef, fmt.Errorf("upgrading to actors v16: %w", err) + } + + // Persist the result. + newRoot, err := adtStore.Put(ctx, &vmstate.StateRoot{ + Version: vmstate.StateTreeVersion5, + Actors: newHamtRoot, + Info: stateRoot.Info, + }) + if err != nil { + return cid.Undef, fmt.Errorf("failed to persist new state root: %w", err) + } + + // Persists the new tree and shuts down the flush worker + if err := writeStore.Flush(ctx); err != nil { + return cid.Undef, fmt.Errorf("writeStore flush failed: %w", err) + } + + if err := writeStore.Shutdown(ctx); err != nil { + return cid.Undef, fmt.Errorf("writeStore shutdown failed: %w", err) + } + + return newRoot, nil +} + func (c *ChainFork) GetForkUpgrade() *config.ForkUpgradeConfig { return c.forkUpgrade } diff --git a/pkg/gen/genesis/miners.go b/pkg/gen/genesis/miners.go index 8ab77c782a..4903c24c80 100644 --- a/pkg/gen/genesis/miners.go +++ b/pkg/gen/genesis/miners.go @@ -320,7 +320,7 @@ func SetupStorageMiners(ctx context.Context, } rawPow = big.Add(rawPow, big.NewInt(int64(m.SectorSize))) - sectorWeight := builtin.QAPowerForWeight(m.SectorSize, minerInfos[i].presealExp, big.Zero(), types.DealWeight(&preseal.Deal)) + sectorWeight := builtin.QAPowerForWeight(m.SectorSize, minerInfos[i].presealExp, types.DealWeight(&preseal.Deal)) minerInfos[i].sectorWeight = append(minerInfos[i].sectorWeight, sectorWeight) qaPow = big.Add(qaPow, sectorWeight) } diff --git a/pkg/vm/register/default.go b/pkg/vm/register/default.go index 8494915660..ba0231fb1c 100644 --- a/pkg/vm/register/default.go +++ b/pkg/vm/register/default.go @@ -45,6 +45,7 @@ func GetDefaultActros() *dispatch.CodeLoader { DefaultActorBuilder.AddMany(actorstypes.Version13, dispatch.ActorsVersionPredicate(actorstypes.Version13), builtin.MakeRegistry(actorstypes.Version13)) DefaultActorBuilder.AddMany(actorstypes.Version14, dispatch.ActorsVersionPredicate(actorstypes.Version14), builtin.MakeRegistry(actorstypes.Version14)) DefaultActorBuilder.AddMany(actorstypes.Version15, dispatch.ActorsVersionPredicate(actorstypes.Version15), builtin.MakeRegistry(actorstypes.Version15)) + DefaultActorBuilder.AddMany(actorstypes.Version16, dispatch.ActorsVersionPredicate(actorstypes.Version16), builtin.MakeRegistry(actorstypes.Version16)) defaultActors = DefaultActorBuilder.Build() }) diff --git a/venus-devtool/go.mod b/venus-devtool/go.mod index 8bbed3f411..7ff9b9ba52 100644 --- a/venus-devtool/go.mod +++ b/venus-devtool/go.mod @@ -11,8 +11,8 @@ require ( github.com/filecoin-project/go-f3 v0.7.3 github.com/filecoin-project/go-fil-markets v1.28.3 github.com/filecoin-project/go-jsonrpc v0.7.0 - github.com/filecoin-project/go-state-types v0.15.0 - github.com/filecoin-project/lotus v1.31.0 + github.com/filecoin-project/go-state-types v0.16.0-rc1 + github.com/filecoin-project/lotus v1.32.0-rc1 github.com/filecoin-project/venus v0.0.0-00010101000000-000000000000 github.com/google/uuid v1.6.0 github.com/ipfs/go-block-format v0.2.0 @@ -58,7 +58,7 @@ require ( github.com/drand/kyber v1.3.1 // indirect github.com/drand/kyber-bls12381 v0.3.1 // indirect github.com/dustin/go-humanize v1.0.1 // indirect - github.com/filecoin-project/filecoin-ffi v1.30.0 // indirect + github.com/filecoin-project/filecoin-ffi v1.31.0 // indirect github.com/filecoin-project/go-amt-ipld/v2 v2.1.1-0.20201006184820-924ee87a1349 // indirect github.com/filecoin-project/go-amt-ipld/v3 v3.1.0 // indirect github.com/filecoin-project/go-amt-ipld/v4 v4.4.0 // indirect @@ -184,7 +184,7 @@ require ( github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/shirou/gopsutil v2.18.12+incompatible // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect - github.com/stretchr/testify v1.9.0 // indirect + github.com/stretchr/testify v1.10.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasttemplate v1.1.0 // indirect github.com/whyrusleeping/bencher v0.0.0-20190829221104-bb6607aa8bba // indirect diff --git a/venus-devtool/go.sum b/venus-devtool/go.sum index 8a781f3c6f..78962891b1 100644 --- a/venus-devtool/go.sum +++ b/venus-devtool/go.sum @@ -276,16 +276,16 @@ github.com/filecoin-project/go-state-types v0.0.0-20201102161440-c8033295a1fc/go github.com/filecoin-project/go-state-types v0.1.0/go.mod h1:ezYnPf0bNkTsDibL/psSz5dy4B5awOJ/E7P2Saeep8g= github.com/filecoin-project/go-state-types v0.1.4/go.mod h1:xCA/WfKlC2zcn3fUmDv4IrzznwS98X5XW/irUP3Lhxg= github.com/filecoin-project/go-state-types v0.1.6/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q= -github.com/filecoin-project/go-state-types v0.15.0 h1:GaUSCti0tGMzLg7fVpRjtNVGBvirbMFzLfyWbR+qzWE= -github.com/filecoin-project/go-state-types v0.15.0/go.mod h1:2okQFn4DVOt5Bs6OFh0lLSzn8p7Vczh8XjgaKLKhKgI= +github.com/filecoin-project/go-state-types v0.16.0-rc1 h1:/51MhupBAjfmWygUKDZCdLOzAnKFcayPHX9ApTswgmo= +github.com/filecoin-project/go-state-types v0.16.0-rc1/go.mod h1:4rjTgHP6LWrkQXQCgx+dRGDa0gnk4WiJVCFwZtuDOGE= github.com/filecoin-project/go-statemachine v0.0.0-20200925024713-05bd7c71fbfe/go.mod h1:FGwQgZAt2Gh5mjlwJUlVB62JeYdo+if0xWxSEfBD9ig= github.com/filecoin-project/go-statemachine v1.0.3 h1:N07o6alys+V1tNoSTi4WuuoeNC4erS/6jE74+NsgQuk= github.com/filecoin-project/go-statemachine v1.0.3/go.mod h1:jZdXXiHa61n4NmgWFG4w8tnqgvZVHYbJ3yW7+y8bF54= github.com/filecoin-project/go-statestore v0.1.0/go.mod h1:LFc9hD+fRxPqiHiaqUEZOinUJB4WARkRfNl10O7kTnI= github.com/filecoin-project/go-statestore v0.2.0 h1:cRRO0aPLrxKQCZ2UOQbzFGn4WDNdofHZoGPjfNaAo5Q= github.com/filecoin-project/go-statestore v0.2.0/go.mod h1:8sjBYbS35HwPzct7iT4lIXjLlYyPor80aU7t7a/Kspo= -github.com/filecoin-project/lotus v1.31.0 h1:FNCn8jSuC5RJSspMXNKI2gDkrxRIsHh1MCHnoUME8ao= -github.com/filecoin-project/lotus v1.31.0/go.mod h1:vvxUCDAAnGC1RwsWStwTr8+LgBlmT+9uEs/SIRfa6aU= +github.com/filecoin-project/lotus v1.32.0-rc1 h1:S7zaMcE+ypGJsEzcNOixyDhXCjpJVWYhuaZy/i/M/I0= +github.com/filecoin-project/lotus v1.32.0-rc1/go.mod h1:ifMbg5DByQRfrD8trEeHEoeCwJrPi15qRG0V4NkViY0= github.com/filecoin-project/pubsub v1.0.0 h1:ZTmT27U07e54qV1mMiQo4HDr0buo8I1LDHBYLXlsNXM= github.com/filecoin-project/pubsub v1.0.0/go.mod h1:GkpB33CcUtUNrLPhJgfdy4FDx4OMNR9k+46DHx/Lqrg= github.com/filecoin-project/specs-actors v0.9.13/go.mod h1:TS1AW/7LbG+615j4NsjMK1qlpAwaFsG9w0V2tg2gSao= @@ -1093,8 +1093,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/stvp/go-udp-testing v0.0.0-20201019212854-469649b16807/go.mod h1:7jxmlfBCDBXRzr0eAQJ48XC1hBu1np4CS5+cHEYfwpc= github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= github.com/twmb/murmur3 v1.1.6 h1:mqrRot1BRxm+Yct+vavLMou2/iJt0tNVTTC0QoIjaZg= diff --git a/venus-devtool/inline-gen/inlinegen-data.json b/venus-devtool/inline-gen/inlinegen-data.json index 34f4bcea03..ac9589a2ad 100644 --- a/venus-devtool/inline-gen/inlinegen-data.json +++ b/venus-devtool/inline-gen/inlinegen-data.json @@ -1,7 +1,7 @@ { - "actorVersions": [0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], - "latestActorsVersion": 15, + "actorVersions": [0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], + "latestActorsVersion": 16, - "networkVersions": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24], - "latestNetworkVersion": 24 + "networkVersions": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25], + "latestNetworkVersion": 25 } diff --git a/venus-shared/actors/builtin-actors-code/v16.tar.zst b/venus-shared/actors/builtin-actors-code/v16.tar.zst new file mode 100644 index 0000000000..4badc6def3 Binary files /dev/null and b/venus-shared/actors/builtin-actors-code/v16.tar.zst differ diff --git a/venus-shared/actors/builtin/account/actor.go b/venus-shared/actors/builtin/account/actor.go index cdfbae825b..a738806cfd 100644 --- a/venus-shared/actors/builtin/account/actor.go +++ b/venus-shared/actors/builtin/account/actor.go @@ -30,10 +30,10 @@ import ( builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin" - builtin15 "github.com/filecoin-project/go-state-types/builtin" + builtin16 "github.com/filecoin-project/go-state-types/builtin" ) -var Methods = builtin15.MethodsAccount +var Methods = builtin16.MethodsAccount func Load(store adt.Store, act *types.Actor) (State, error) { if name, av, ok := actors.GetActorMetaByCode(act.Code); ok { @@ -67,6 +67,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) { case actorstypes.Version15: return load15(store, act.Head) + case actorstypes.Version16: + return load16(store, act.Head) + } } @@ -146,6 +149,9 @@ func MakeState(store adt.Store, av actorstypes.Version, addr address.Address) (S case actorstypes.Version15: return make15(store, addr) + case actorstypes.Version16: + return make16(store, addr) + } return nil, fmt.Errorf("unknown actor version %d", av) } @@ -178,5 +184,6 @@ func AllCodes() []cid.Cid { (&state13{}).Code(), (&state14{}).Code(), (&state15{}).Code(), + (&state16{}).Code(), } } diff --git a/venus-shared/actors/builtin/account/state.v16.go b/venus-shared/actors/builtin/account/state.v16.go new file mode 100644 index 0000000000..3b73135a5d --- /dev/null +++ b/venus-shared/actors/builtin/account/state.v16.go @@ -0,0 +1,65 @@ +// FETCHED FROM LOTUS: builtin/account/state.go.template + +package account + +import ( + "fmt" + + actorstypes "github.com/filecoin-project/go-state-types/actors" + + "github.com/filecoin-project/go-address" + "github.com/ipfs/go-cid" + + "github.com/filecoin-project/go-state-types/manifest" + "github.com/filecoin-project/venus/venus-shared/actors" + "github.com/filecoin-project/venus/venus-shared/actors/adt" + + account16 "github.com/filecoin-project/go-state-types/builtin/v16/account" +) + +var _ State = (*state16)(nil) + +func load16(store adt.Store, root cid.Cid) (State, error) { + out := state16{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +func make16(store adt.Store, addr address.Address) (State, error) { + out := state16{store: store} + out.State = account16.State{Address: addr} + return &out, nil +} + +type state16 struct { + account16.State + store adt.Store +} + +func (s *state16) PubkeyAddress() (address.Address, error) { + return s.Address, nil +} + +func (s *state16) GetState() interface{} { + return &s.State +} + +func (s *state16) ActorKey() string { + return manifest.AccountKey +} + +func (s *state16) ActorVersion() actorstypes.Version { + return actorstypes.Version16 +} + +func (s *state16) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/venus-shared/actors/builtin/builtin.go b/venus-shared/actors/builtin/builtin.go index 8f4abad11e..63fc735f95 100644 --- a/venus-shared/actors/builtin/builtin.go +++ b/venus-shared/actors/builtin/builtin.go @@ -29,8 +29,8 @@ import ( "github.com/filecoin-project/venus/venus-shared/actors" + minertypes "github.com/filecoin-project/go-state-types/builtin/v15/miner" smoothingtypes "github.com/filecoin-project/go-state-types/builtin/v8/util/smoothing" - minertypes "github.com/filecoin-project/go-state-types/builtin/v9/miner" ) var InitActorAddr = builtin.InitActorAddr @@ -66,8 +66,8 @@ type ExtendedSectorInfo = proof.ExtendedSectorInfo type PoStProof = proof.PoStProof type FilterEstimate = smoothingtypes.FilterEstimate -func QAPowerForWeight(size abi.SectorSize, duration abi.ChainEpoch, dealWeight, verifiedWeight abi.DealWeight) abi.StoragePower { - return minertypes.QAPowerForWeight(size, duration, dealWeight, verifiedWeight) +func QAPowerForWeight(size abi.SectorSize, duration abi.ChainEpoch, verifiedWeight abi.DealWeight) abi.StoragePower { + return minertypes.QAPowerForWeight(size, duration, verifiedWeight) } func ActorNameByCode(c cid.Cid) string { diff --git a/venus-shared/actors/builtin/builtin.go.template b/venus-shared/actors/builtin/builtin.go.template index b86182568a..f340479d17 100644 --- a/venus-shared/actors/builtin/builtin.go.template +++ b/venus-shared/actors/builtin/builtin.go.template @@ -21,7 +21,7 @@ import ( "github.com/filecoin-project/venus/venus-shared/actors" - minertypes "github.com/filecoin-project/go-state-types/builtin/v9/miner" + minertypes "github.com/filecoin-project/go-state-types/builtin/v15/miner" smoothingtypes "github.com/filecoin-project/go-state-types/builtin/v8/util/smoothing" ) @@ -58,8 +58,8 @@ type ExtendedSectorInfo = proof.ExtendedSectorInfo type PoStProof = proof.PoStProof type FilterEstimate = smoothingtypes.FilterEstimate -func QAPowerForWeight(size abi.SectorSize, duration abi.ChainEpoch, dealWeight, verifiedWeight abi.DealWeight) abi.StoragePower { - return minertypes.QAPowerForWeight(size, duration, dealWeight, verifiedWeight) +func QAPowerForWeight(size abi.SectorSize, duration abi.ChainEpoch, verifiedWeight abi.DealWeight) abi.StoragePower { + return minertypes.QAPowerForWeight(size, duration, verifiedWeight) } func ActorNameByCode(c cid.Cid) string { diff --git a/venus-shared/actors/builtin/cron/actor.go b/venus-shared/actors/builtin/cron/actor.go index 2214fc5de5..afcf3357f0 100644 --- a/venus-shared/actors/builtin/cron/actor.go +++ b/venus-shared/actors/builtin/cron/actor.go @@ -26,7 +26,7 @@ import ( builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin" - builtin15 "github.com/filecoin-project/go-state-types/builtin" + builtin16 "github.com/filecoin-project/go-state-types/builtin" ) func Load(store adt.Store, act *types.Actor) (State, error) { @@ -61,6 +61,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) { case actorstypes.Version15: return load15(store, act.Head) + case actorstypes.Version16: + return load16(store, act.Head) + } } @@ -140,13 +143,16 @@ func MakeState(store adt.Store, av actorstypes.Version) (State, error) { case actorstypes.Version15: return make15(store) + case actorstypes.Version16: + return make16(store) + } return nil, fmt.Errorf("unknown actor version %d", av) } var ( - Address = builtin15.CronActorAddr - Methods = builtin15.MethodsCron + Address = builtin16.CronActorAddr + Methods = builtin16.MethodsCron ) type State interface { @@ -174,5 +180,6 @@ func AllCodes() []cid.Cid { (&state13{}).Code(), (&state14{}).Code(), (&state15{}).Code(), + (&state16{}).Code(), } } diff --git a/venus-shared/actors/builtin/cron/state.v16.go b/venus-shared/actors/builtin/cron/state.v16.go new file mode 100644 index 0000000000..be6f223ed4 --- /dev/null +++ b/venus-shared/actors/builtin/cron/state.v16.go @@ -0,0 +1,59 @@ +// FETCHED FROM LOTUS: builtin/cron/state.go.template + +package cron + +import ( + "fmt" + + "github.com/ipfs/go-cid" + + actorstypes "github.com/filecoin-project/go-state-types/actors" + "github.com/filecoin-project/go-state-types/manifest" + "github.com/filecoin-project/venus/venus-shared/actors" + "github.com/filecoin-project/venus/venus-shared/actors/adt" + + cron16 "github.com/filecoin-project/go-state-types/builtin/v16/cron" +) + +var _ State = (*state16)(nil) + +func load16(store adt.Store, root cid.Cid) (State, error) { + out := state16{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +func make16(store adt.Store) (State, error) { + out := state16{store: store} + out.State = *cron16.ConstructState(cron16.BuiltInEntries()) + return &out, nil +} + +type state16 struct { + cron16.State + store adt.Store +} + +func (s *state16) GetState() interface{} { + return &s.State +} + +func (s *state16) ActorKey() string { + return manifest.CronKey +} + +func (s *state16) ActorVersion() actorstypes.Version { + return actorstypes.Version16 +} + +func (s *state16) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/venus-shared/actors/builtin/datacap/actor.go b/venus-shared/actors/builtin/datacap/actor.go index c38557717c..c33ffc5080 100644 --- a/venus-shared/actors/builtin/datacap/actor.go +++ b/venus-shared/actors/builtin/datacap/actor.go @@ -10,7 +10,7 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" actorstypes "github.com/filecoin-project/go-state-types/actors" - builtin15 "github.com/filecoin-project/go-state-types/builtin" + builtin16 "github.com/filecoin-project/go-state-types/builtin" "github.com/filecoin-project/go-state-types/cbor" "github.com/filecoin-project/go-state-types/manifest" @@ -20,8 +20,8 @@ import ( ) var ( - Address = builtin15.DatacapActorAddr - Methods = builtin15.MethodsDatacap + Address = builtin16.DatacapActorAddr + Methods = builtin16.MethodsDatacap ) func Load(store adt.Store, act *types.Actor) (State, error) { @@ -53,6 +53,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) { case actorstypes.Version15: return load15(store, act.Head) + case actorstypes.Version16: + return load16(store, act.Head) + } } @@ -83,6 +86,9 @@ func MakeState(store adt.Store, av actorstypes.Version, governor address.Address case actorstypes.Version15: return make15(store, governor, bitwidth) + case actorstypes.Version16: + return make16(store, governor, bitwidth) + default: return nil, fmt.Errorf("datacap actor only valid for actors v9 and above, got %d", av) } @@ -110,5 +116,6 @@ func AllCodes() []cid.Cid { (&state13{}).Code(), (&state14{}).Code(), (&state15{}).Code(), + (&state16{}).Code(), } } diff --git a/venus-shared/actors/builtin/datacap/state.v16.go b/venus-shared/actors/builtin/datacap/state.v16.go new file mode 100644 index 0000000000..dda7f4a928 --- /dev/null +++ b/venus-shared/actors/builtin/datacap/state.v16.go @@ -0,0 +1,84 @@ +// FETCHED FROM LOTUS: builtin/datacap/state.go.template + +package datacap + +import ( + "fmt" + + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + "github.com/ipfs/go-cid" + + actorstypes "github.com/filecoin-project/go-state-types/actors" + "github.com/filecoin-project/venus/venus-shared/actors" + "github.com/filecoin-project/venus/venus-shared/actors/adt" + + datacap16 "github.com/filecoin-project/go-state-types/builtin/v16/datacap" + adt16 "github.com/filecoin-project/go-state-types/builtin/v16/util/adt" + "github.com/filecoin-project/go-state-types/manifest" +) + +var _ State = (*state16)(nil) + +func load16(store adt.Store, root cid.Cid) (State, error) { + out := state16{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +func make16(store adt.Store, governor address.Address, bitwidth uint64) (State, error) { + out := state16{store: store} + s, err := datacap16.ConstructState(store, governor, bitwidth) + if err != nil { + return nil, err + } + + out.State = *s + + return &out, nil +} + +type state16 struct { + datacap16.State + store adt.Store +} + +func (s *state16) Governor() (address.Address, error) { + return s.State.Governor, nil +} + +func (s *state16) GetState() interface{} { + return &s.State +} + +func (s *state16) ForEachClient(cb func(addr address.Address, dcap abi.StoragePower) error) error { + return forEachClient(s.store, actors.Version16, s.verifiedClients, cb) +} + +func (s *state16) verifiedClients() (adt.Map, error) { + return adt16.AsMap(s.store, s.Token.Balances, int(s.Token.HamtBitWidth)) +} + +func (s *state16) VerifiedClientDataCap(addr address.Address) (bool, abi.StoragePower, error) { + return getDataCap(s.store, actors.Version16, s.verifiedClients, addr) +} + +func (s *state16) ActorKey() string { + return manifest.DatacapKey +} + +func (s *state16) ActorVersion() actorstypes.Version { + return actorstypes.Version16 +} + +func (s *state16) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/venus-shared/actors/builtin/evm/actor.go b/venus-shared/actors/builtin/evm/actor.go index 0c431e0a13..18e01b411d 100644 --- a/venus-shared/actors/builtin/evm/actor.go +++ b/venus-shared/actors/builtin/evm/actor.go @@ -17,10 +17,10 @@ import ( "github.com/filecoin-project/go-state-types/exitcode" "github.com/filecoin-project/go-state-types/manifest" - builtin15 "github.com/filecoin-project/go-state-types/builtin" + builtin16 "github.com/filecoin-project/go-state-types/builtin" ) -var Methods = builtin15.MethodsEVM +var Methods = builtin16.MethodsEVM // See https://github.com/filecoin-project/builtin-actors/blob/6e781444cee5965278c46ef4ffe1fb1970f18d7d/actors/evm/src/lib.rs#L35-L42 const ( @@ -60,6 +60,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) { case actorstypes.Version15: return load15(store, act.Head) + case actorstypes.Version16: + return load16(store, act.Head) + } } @@ -87,6 +90,9 @@ func MakeState(store adt.Store, av actorstypes.Version, bytecode cid.Cid) (State case actorstypes.Version15: return make15(store, bytecode) + case actorstypes.Version16: + return make16(store, bytecode) + default: return nil, fmt.Errorf("evm actor only valid for actors v10 and above, got %d", av) } diff --git a/venus-shared/actors/builtin/evm/state.v16.go b/venus-shared/actors/builtin/evm/state.v16.go new file mode 100644 index 0000000000..fd4fb2af0b --- /dev/null +++ b/venus-shared/actors/builtin/evm/state.v16.go @@ -0,0 +1,74 @@ +// FETCHED FROM LOTUS: builtin/evm/state.go.template + +package evm + +import ( + "github.com/ipfs/go-cid" + + "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/venus/venus-shared/actors/adt" + + evm16 "github.com/filecoin-project/go-state-types/builtin/v16/evm" +) + +var _ State = (*state16)(nil) + +func load16(store adt.Store, root cid.Cid) (State, error) { + out := state16{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +func make16(store adt.Store, bytecode cid.Cid) (State, error) { + out := state16{store: store} + s, err := evm16.ConstructState(store, bytecode) + if err != nil { + return nil, err + } + + out.State = *s + + return &out, nil +} + +type state16 struct { + evm16.State + store adt.Store +} + +func (s *state16) Nonce() (uint64, error) { + return s.State.Nonce, nil +} + +func (s *state16) IsAlive() (bool, error) { + return s.State.Tombstone == nil, nil +} + +func (s *state16) GetState() interface{} { + return &s.State +} + +func (s *state16) GetBytecodeCID() (cid.Cid, error) { + return s.State.Bytecode, nil +} + +func (s *state16) GetBytecodeHash() ([32]byte, error) { + return s.State.BytecodeHash, nil +} + +func (s *state16) GetBytecode() ([]byte, error) { + bc, err := s.GetBytecodeCID() + if err != nil { + return nil, err + } + + var byteCode abi.CborBytesTransparent + if err := s.store.Get(s.store.Context(), bc, &byteCode); err != nil { + return nil, err + } + + return byteCode, nil +} diff --git a/venus-shared/actors/builtin/init/actor.go b/venus-shared/actors/builtin/init/actor.go index 1057f8f7c8..8fe79b5461 100644 --- a/venus-shared/actors/builtin/init/actor.go +++ b/venus-shared/actors/builtin/init/actor.go @@ -32,12 +32,12 @@ import ( builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin" - builtin15 "github.com/filecoin-project/go-state-types/builtin" + builtin16 "github.com/filecoin-project/go-state-types/builtin" ) var ( - Address = builtin15.InitActorAddr - Methods = builtin15.MethodsInit + Address = builtin16.InitActorAddr + Methods = builtin16.MethodsInit ) func Load(store adt.Store, act *types.Actor) (State, error) { @@ -72,6 +72,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) { case actorstypes.Version15: return load15(store, act.Head) + case actorstypes.Version16: + return load16(store, act.Head) + } } @@ -151,6 +154,9 @@ func MakeState(store adt.Store, av actorstypes.Version, networkName string) (Sta case actorstypes.Version15: return make15(store, networkName) + case actorstypes.Version16: + return make16(store, networkName) + } return nil, fmt.Errorf("unknown actor version %d", av) } @@ -206,5 +212,6 @@ func AllCodes() []cid.Cid { (&state13{}).Code(), (&state14{}).Code(), (&state15{}).Code(), + (&state16{}).Code(), } } diff --git a/venus-shared/actors/builtin/init/state.v16.go b/venus-shared/actors/builtin/init/state.v16.go new file mode 100644 index 0000000000..a79c7627a7 --- /dev/null +++ b/venus-shared/actors/builtin/init/state.v16.go @@ -0,0 +1,148 @@ +// FETCHED FROM LOTUS: builtin/init/state.go.template + +package init + +import ( + "crypto/sha256" + "fmt" + + "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" + + actorstypes "github.com/filecoin-project/go-state-types/actors" + "github.com/filecoin-project/venus/venus-shared/actors" + "github.com/filecoin-project/venus/venus-shared/actors/adt" + + "github.com/filecoin-project/go-state-types/manifest" + + builtin16 "github.com/filecoin-project/go-state-types/builtin" + init16 "github.com/filecoin-project/go-state-types/builtin/v16/init" + adt16 "github.com/filecoin-project/go-state-types/builtin/v16/util/adt" +) + +var _ State = (*state16)(nil) + +func load16(store adt.Store, root cid.Cid) (State, error) { + out := state16{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +func make16(store adt.Store, networkName string) (State, error) { + out := state16{store: store} + + s, err := init16.ConstructState(store, networkName) + if err != nil { + return nil, err + } + + out.State = *s + + return &out, nil +} + +type state16 struct { + init16.State + store adt.Store +} + +func (s *state16) ResolveAddress(address address.Address) (address.Address, bool, error) { + return s.State.ResolveAddress(s.store, address) +} + +func (s *state16) MapAddressToNewID(address address.Address) (address.Address, error) { + return s.State.MapAddressToNewID(s.store, address) +} + +func (s *state16) ForEachActor(cb func(id abi.ActorID, address address.Address) error) error { + addrs, err := adt16.AsMap(s.store, s.State.AddressMap, builtin16.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 *state16) NetworkName() (string, error) { + return string(s.State.NetworkName), nil +} + +func (s *state16) SetNetworkName(name string) error { + s.State.NetworkName = name + return nil +} + +func (s *state16) SetNextID(id abi.ActorID) error { + s.State.NextID = id + return nil +} + +func (s *state16) Remove(addrs ...address.Address) (err error) { + m, err := adt16.AsMap(s.store, s.State.AddressMap, builtin16.DefaultHamtBitwidth) + if err != nil { + return err + } + for _, addr := range addrs { + if err = m.Delete(abi.AddrKey(addr)); err != nil { + return fmt.Errorf("failed to delete entry for address: %s; err: %w", addr, err) + } + } + amr, err := m.Root() + if err != nil { + return fmt.Errorf("failed to get address map root: %w", err) + } + s.State.AddressMap = amr + return nil +} + +func (s *state16) SetAddressMap(mcid cid.Cid) error { + s.State.AddressMap = mcid + return nil +} + +func (s *state16) GetState() interface{} { + return &s.State +} + +func (s *state16) AddressMap() (adt.Map, error) { + return adt16.AsMap(s.store, s.State.AddressMap, builtin16.DefaultHamtBitwidth) +} + +func (s *state16) AddressMapBitWidth() int { + return builtin16.DefaultHamtBitwidth +} + +func (s *state16) AddressMapHashFunction() func(input []byte) []byte { + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } +} + +func (s *state16) ActorKey() string { + return manifest.InitKey +} + +func (s *state16) ActorVersion() actorstypes.Version { + return actorstypes.Version16 +} + +func (s *state16) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/venus-shared/actors/builtin/market/actor.go b/venus-shared/actors/builtin/market/actor.go index a64eb5ba02..f3c334cbc4 100644 --- a/venus-shared/actors/builtin/market/actor.go +++ b/venus-shared/actors/builtin/market/actor.go @@ -80,6 +80,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) { case actorstypes.Version15: return load15(store, act.Head) + case actorstypes.Version16: + return load16(store, act.Head) + } } @@ -159,6 +162,9 @@ func MakeState(store adt.Store, av actorstypes.Version) (State, error) { case actorstypes.Version15: return make15(store) + case actorstypes.Version16: + return make16(store) + } return nil, fmt.Errorf("unknown actor version %d", av) } @@ -178,9 +184,10 @@ type State interface { States() (DealStates, error) ProposalsChanged(State) (bool, error) Proposals() (DealProposals, error) + PendingProposals() (PendingProposals, error) VerifyDealsForActivation( minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch, - ) (weight, verifiedWeight abi.DealWeight, err error) + ) (verifiedWeight abi.DealWeight, err error) NextID() (abi.DealID, error) GetState() interface{} GetAllocationIdForPendingDeal(dealId abi.DealID) (verifregtypes.AllocationId, error) @@ -207,6 +214,10 @@ type DealProposals interface { decode(*cbg.Deferred) (*markettypes.DealProposal, error) } +type PendingProposals interface { + Has(proposalCid cid.Cid) (bool, error) +} + type PublishStorageDealsReturn interface { DealIDs() ([]abi.DealID, error) // Note that this index is based on the batch of deals that were published, NOT the DealID @@ -266,6 +277,9 @@ func DecodePublishStorageDealsReturn(b []byte, nv network.Version) (PublishStora case actorstypes.Version15: return decodePublishStorageDealsReturn15(b) + case actorstypes.Version16: + return decodePublishStorageDealsReturn16(b) + } return nil, fmt.Errorf("unknown actor version %d", av) } @@ -394,5 +408,6 @@ func AllCodes() []cid.Cid { (&state13{}).Code(), (&state14{}).Code(), (&state15{}).Code(), + (&state16{}).Code(), } } diff --git a/venus-shared/actors/builtin/market/actor.go.template b/venus-shared/actors/builtin/market/actor.go.template index d2897eb668..d3efd695e5 100644 --- a/venus-shared/actors/builtin/market/actor.go.template +++ b/venus-shared/actors/builtin/market/actor.go.template @@ -90,9 +90,10 @@ type State interface { States() (DealStates, error) ProposalsChanged(State) (bool, error) Proposals() (DealProposals, error) + PendingProposals() (PendingProposals, error) VerifyDealsForActivation( minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch, - ) (weight, verifiedWeight abi.DealWeight, err error) + ) (verifiedWeight abi.DealWeight, err error) NextID() (abi.DealID, error) GetState() interface{} GetAllocationIdForPendingDeal(dealId abi.DealID) (verifregtypes.AllocationId, error) @@ -119,6 +120,9 @@ type DealProposals interface { decode(*cbg.Deferred) (*markettypes.DealProposal, error) } +type PendingProposals interface { + Has(proposalCid cid.Cid) (bool, error) +} type PublishStorageDealsReturn interface { DealIDs() ([]abi.DealID, error) diff --git a/venus-shared/actors/builtin/market/state.sep.go.template b/venus-shared/actors/builtin/market/state.sep.go.template index 40ec98dd69..8456a9d544 100644 --- a/venus-shared/actors/builtin/market/state.sep.go.template +++ b/venus-shared/actors/builtin/market/state.sep.go.template @@ -31,7 +31,7 @@ import ( markettypes "github.com/filecoin-project/go-state-types/builtin/v9/market" adt{{.v}} "github.com/filecoin-project/go-state-types/builtin{{.import}}util/adt" {{end}} -{{if (ge .v 9)}} +{{if (ge .v 3)}} "github.com/filecoin-project/go-state-types/builtin" {{end}} ) @@ -129,6 +129,14 @@ func (s *state{{.v}}) Proposals() (DealProposals, error) { return &dealProposals{{.v}}{proposalArray}, nil } +func (s *state{{.v}}) PendingProposals() (PendingProposals, error) { + proposalCidSet, err := adt{{.v}}.AsSet(s.store, s.State.PendingProposals{{if (ge .v 3)}}, builtin.DefaultHamtBitwidth{{end}}) + if err != nil { + return nil, err + } + return &pendingProposals{{.v}}{proposalCidSet}, nil +} + func (s *state{{.v}}) EscrowTable() (BalanceTable, error) { bt, err := adt{{.v}}.AsBalanceTable(s.store, s.State.EscrowTable) if err != nil { @@ -147,9 +155,9 @@ func (s *state{{.v}}) LockedTable() (BalanceTable, error) { func (s *state{{.v}}) VerifyDealsForActivation( minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch, -) (weight, verifiedWeight abi.DealWeight, err error) { - w, vw{{if (ge .v 2)}}, _{{end}}, err := market{{.v}}.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) - return w, vw, err +) (verifiedWeight abi.DealWeight, err error) { + _, vw{{if (ge .v 2)}}, _{{end}}, err := market{{.v}}.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) + return vw, err } func (s *state{{.v}}) NextID() (abi.DealID, error) { @@ -309,6 +317,14 @@ func (s *dealProposals{{.v}}) array() adt.Array { return s.Array } +type pendingProposals{{.v}} struct { + *adt{{.v}}.Set +} + +func (s *pendingProposals{{.v}}) Has(proposalCid cid.Cid) (bool, error) { + return s.Set.Has(abi.CidKey(proposalCid)) +} + func fromV{{.v}}DealProposal(v{{.v}} market{{.v}}.DealProposal) (DealProposal, error) { {{if (le .v 7)}} label, err := labelFromGoString(v{{.v}}.Label) diff --git a/venus-shared/actors/builtin/market/state.v0.go b/venus-shared/actors/builtin/market/state.v0.go index d508b92b70..c5f10eb93f 100644 --- a/venus-shared/actors/builtin/market/state.v0.go +++ b/venus-shared/actors/builtin/market/state.v0.go @@ -108,6 +108,14 @@ func (s *state0) Proposals() (DealProposals, error) { return &dealProposals0{proposalArray}, nil } +func (s *state0) PendingProposals() (PendingProposals, error) { + proposalCidSet, err := adt0.AsSet(s.store, s.State.PendingProposals) + if err != nil { + return nil, err + } + return &pendingProposals0{proposalCidSet}, nil +} + func (s *state0) EscrowTable() (BalanceTable, error) { bt, err := adt0.AsBalanceTable(s.store, s.State.EscrowTable) if err != nil { @@ -126,9 +134,9 @@ func (s *state0) LockedTable() (BalanceTable, error) { func (s *state0) VerifyDealsForActivation( minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch, -) (weight, verifiedWeight abi.DealWeight, err error) { - w, vw, err := market0.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) - return w, vw, err +) (verifiedWeight abi.DealWeight, err error) { + _, vw, err := market0.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) + return vw, err } func (s *state0) NextID() (abi.DealID, error) { @@ -286,6 +294,14 @@ func (s *dealProposals0) array() adt.Array { return s.Array } +type pendingProposals0 struct { + *adt0.Set +} + +func (s *pendingProposals0) Has(proposalCid cid.Cid) (bool, error) { + return s.Set.Has(abi.CidKey(proposalCid)) +} + func fromV0DealProposal(v0 market0.DealProposal) (DealProposal, error) { label, err := labelFromGoString(v0.Label) diff --git a/venus-shared/actors/builtin/market/state.v10.go b/venus-shared/actors/builtin/market/state.v10.go index ce8903bbc1..2bdccda28f 100644 --- a/venus-shared/actors/builtin/market/state.v10.go +++ b/venus-shared/actors/builtin/market/state.v10.go @@ -109,6 +109,14 @@ func (s *state10) Proposals() (DealProposals, error) { return &dealProposals10{proposalArray}, nil } +func (s *state10) PendingProposals() (PendingProposals, error) { + proposalCidSet, err := adt10.AsSet(s.store, s.State.PendingProposals, builtin.DefaultHamtBitwidth) + if err != nil { + return nil, err + } + return &pendingProposals10{proposalCidSet}, nil +} + func (s *state10) EscrowTable() (BalanceTable, error) { bt, err := adt10.AsBalanceTable(s.store, s.State.EscrowTable) if err != nil { @@ -127,9 +135,9 @@ func (s *state10) LockedTable() (BalanceTable, error) { func (s *state10) VerifyDealsForActivation( minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch, -) (weight, verifiedWeight abi.DealWeight, err error) { - w, vw, _, err := market10.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) - return w, vw, err +) (verifiedWeight abi.DealWeight, err error) { + _, vw, _, err := market10.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) + return vw, err } func (s *state10) NextID() (abi.DealID, error) { @@ -287,6 +295,14 @@ func (s *dealProposals10) array() adt.Array { return s.Array } +type pendingProposals10 struct { + *adt10.Set +} + +func (s *pendingProposals10) Has(proposalCid cid.Cid) (bool, error) { + return s.Set.Has(abi.CidKey(proposalCid)) +} + func fromV10DealProposal(v10 market10.DealProposal) (DealProposal, error) { label, err := fromV10Label(v10.Label) diff --git a/venus-shared/actors/builtin/market/state.v11.go b/venus-shared/actors/builtin/market/state.v11.go index 4b2d734447..1c84b852d8 100644 --- a/venus-shared/actors/builtin/market/state.v11.go +++ b/venus-shared/actors/builtin/market/state.v11.go @@ -109,6 +109,14 @@ func (s *state11) Proposals() (DealProposals, error) { return &dealProposals11{proposalArray}, nil } +func (s *state11) PendingProposals() (PendingProposals, error) { + proposalCidSet, err := adt11.AsSet(s.store, s.State.PendingProposals, builtin.DefaultHamtBitwidth) + if err != nil { + return nil, err + } + return &pendingProposals11{proposalCidSet}, nil +} + func (s *state11) EscrowTable() (BalanceTable, error) { bt, err := adt11.AsBalanceTable(s.store, s.State.EscrowTable) if err != nil { @@ -127,9 +135,9 @@ func (s *state11) LockedTable() (BalanceTable, error) { func (s *state11) VerifyDealsForActivation( minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch, -) (weight, verifiedWeight abi.DealWeight, err error) { - w, vw, _, err := market11.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) - return w, vw, err +) (verifiedWeight abi.DealWeight, err error) { + _, vw, _, err := market11.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) + return vw, err } func (s *state11) NextID() (abi.DealID, error) { @@ -287,6 +295,14 @@ func (s *dealProposals11) array() adt.Array { return s.Array } +type pendingProposals11 struct { + *adt11.Set +} + +func (s *pendingProposals11) Has(proposalCid cid.Cid) (bool, error) { + return s.Set.Has(abi.CidKey(proposalCid)) +} + func fromV11DealProposal(v11 market11.DealProposal) (DealProposal, error) { label, err := fromV11Label(v11.Label) diff --git a/venus-shared/actors/builtin/market/state.v12.go b/venus-shared/actors/builtin/market/state.v12.go index 0689b3d080..f0c5e212a8 100644 --- a/venus-shared/actors/builtin/market/state.v12.go +++ b/venus-shared/actors/builtin/market/state.v12.go @@ -109,6 +109,14 @@ func (s *state12) Proposals() (DealProposals, error) { return &dealProposals12{proposalArray}, nil } +func (s *state12) PendingProposals() (PendingProposals, error) { + proposalCidSet, err := adt12.AsSet(s.store, s.State.PendingProposals, builtin.DefaultHamtBitwidth) + if err != nil { + return nil, err + } + return &pendingProposals12{proposalCidSet}, nil +} + func (s *state12) EscrowTable() (BalanceTable, error) { bt, err := adt12.AsBalanceTable(s.store, s.State.EscrowTable) if err != nil { @@ -127,9 +135,9 @@ func (s *state12) LockedTable() (BalanceTable, error) { func (s *state12) VerifyDealsForActivation( minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch, -) (weight, verifiedWeight abi.DealWeight, err error) { - w, vw, _, err := market12.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) - return w, vw, err +) (verifiedWeight abi.DealWeight, err error) { + _, vw, _, err := market12.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) + return vw, err } func (s *state12) NextID() (abi.DealID, error) { @@ -287,6 +295,14 @@ func (s *dealProposals12) array() adt.Array { return s.Array } +type pendingProposals12 struct { + *adt12.Set +} + +func (s *pendingProposals12) Has(proposalCid cid.Cid) (bool, error) { + return s.Set.Has(abi.CidKey(proposalCid)) +} + func fromV12DealProposal(v12 market12.DealProposal) (DealProposal, error) { label, err := fromV12Label(v12.Label) diff --git a/venus-shared/actors/builtin/market/state.v13.go b/venus-shared/actors/builtin/market/state.v13.go index 176553958e..e467f2f094 100644 --- a/venus-shared/actors/builtin/market/state.v13.go +++ b/venus-shared/actors/builtin/market/state.v13.go @@ -109,6 +109,14 @@ func (s *state13) Proposals() (DealProposals, error) { return &dealProposals13{proposalArray}, nil } +func (s *state13) PendingProposals() (PendingProposals, error) { + proposalCidSet, err := adt13.AsSet(s.store, s.State.PendingProposals, builtin.DefaultHamtBitwidth) + if err != nil { + return nil, err + } + return &pendingProposals13{proposalCidSet}, nil +} + func (s *state13) EscrowTable() (BalanceTable, error) { bt, err := adt13.AsBalanceTable(s.store, s.State.EscrowTable) if err != nil { @@ -127,9 +135,9 @@ func (s *state13) LockedTable() (BalanceTable, error) { func (s *state13) VerifyDealsForActivation( minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch, -) (weight, verifiedWeight abi.DealWeight, err error) { - w, vw, _, err := market13.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) - return w, vw, err +) (verifiedWeight abi.DealWeight, err error) { + _, vw, _, err := market13.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) + return vw, err } func (s *state13) NextID() (abi.DealID, error) { @@ -287,6 +295,14 @@ func (s *dealProposals13) array() adt.Array { return s.Array } +type pendingProposals13 struct { + *adt13.Set +} + +func (s *pendingProposals13) Has(proposalCid cid.Cid) (bool, error) { + return s.Set.Has(abi.CidKey(proposalCid)) +} + func fromV13DealProposal(v13 market13.DealProposal) (DealProposal, error) { label, err := fromV13Label(v13.Label) diff --git a/venus-shared/actors/builtin/market/state.v14.go b/venus-shared/actors/builtin/market/state.v14.go index bbb69dc56b..87aee9c68c 100644 --- a/venus-shared/actors/builtin/market/state.v14.go +++ b/venus-shared/actors/builtin/market/state.v14.go @@ -109,6 +109,14 @@ func (s *state14) Proposals() (DealProposals, error) { return &dealProposals14{proposalArray}, nil } +func (s *state14) PendingProposals() (PendingProposals, error) { + proposalCidSet, err := adt14.AsSet(s.store, s.State.PendingProposals, builtin.DefaultHamtBitwidth) + if err != nil { + return nil, err + } + return &pendingProposals14{proposalCidSet}, nil +} + func (s *state14) EscrowTable() (BalanceTable, error) { bt, err := adt14.AsBalanceTable(s.store, s.State.EscrowTable) if err != nil { @@ -127,9 +135,9 @@ func (s *state14) LockedTable() (BalanceTable, error) { func (s *state14) VerifyDealsForActivation( minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch, -) (weight, verifiedWeight abi.DealWeight, err error) { - w, vw, _, err := market14.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) - return w, vw, err +) (verifiedWeight abi.DealWeight, err error) { + _, vw, _, err := market14.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) + return vw, err } func (s *state14) NextID() (abi.DealID, error) { @@ -287,6 +295,14 @@ func (s *dealProposals14) array() adt.Array { return s.Array } +type pendingProposals14 struct { + *adt14.Set +} + +func (s *pendingProposals14) Has(proposalCid cid.Cid) (bool, error) { + return s.Set.Has(abi.CidKey(proposalCid)) +} + func fromV14DealProposal(v14 market14.DealProposal) (DealProposal, error) { label, err := fromV14Label(v14.Label) diff --git a/venus-shared/actors/builtin/market/state.v15.go b/venus-shared/actors/builtin/market/state.v15.go index 53e6aae9c7..f05ad2578e 100644 --- a/venus-shared/actors/builtin/market/state.v15.go +++ b/venus-shared/actors/builtin/market/state.v15.go @@ -109,6 +109,14 @@ func (s *state15) Proposals() (DealProposals, error) { return &dealProposals15{proposalArray}, nil } +func (s *state15) PendingProposals() (PendingProposals, error) { + proposalCidSet, err := adt15.AsSet(s.store, s.State.PendingProposals, builtin.DefaultHamtBitwidth) + if err != nil { + return nil, err + } + return &pendingProposals15{proposalCidSet}, nil +} + func (s *state15) EscrowTable() (BalanceTable, error) { bt, err := adt15.AsBalanceTable(s.store, s.State.EscrowTable) if err != nil { @@ -127,9 +135,9 @@ func (s *state15) LockedTable() (BalanceTable, error) { func (s *state15) VerifyDealsForActivation( minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch, -) (weight, verifiedWeight abi.DealWeight, err error) { - w, vw, _, err := market15.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) - return w, vw, err +) (verifiedWeight abi.DealWeight, err error) { + _, vw, _, err := market15.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) + return vw, err } func (s *state15) NextID() (abi.DealID, error) { @@ -287,6 +295,14 @@ func (s *dealProposals15) array() adt.Array { return s.Array } +type pendingProposals15 struct { + *adt15.Set +} + +func (s *pendingProposals15) Has(proposalCid cid.Cid) (bool, error) { + return s.Set.Has(abi.CidKey(proposalCid)) +} + func fromV15DealProposal(v15 market15.DealProposal) (DealProposal, error) { label, err := fromV15Label(v15.Label) diff --git a/venus-shared/actors/builtin/market/state.v16.go b/venus-shared/actors/builtin/market/state.v16.go new file mode 100644 index 0000000000..96aaddd5af --- /dev/null +++ b/venus-shared/actors/builtin/market/state.v16.go @@ -0,0 +1,429 @@ +// FETCHED FROM LOTUS: builtin/market/state.go.template + +package market + +import ( + "bytes" + "fmt" + + "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/go-bitfield" + rlepluslazy "github.com/filecoin-project/go-bitfield/rle" + + actorstypes "github.com/filecoin-project/go-state-types/actors" + "github.com/filecoin-project/go-state-types/manifest" + "github.com/filecoin-project/venus/venus-shared/actors" + "github.com/filecoin-project/venus/venus-shared/actors/adt" + verifregtypes "github.com/filecoin-project/venus/venus-shared/actors/builtin/verifreg" + "github.com/filecoin-project/venus/venus-shared/actors/types" + + market16 "github.com/filecoin-project/go-state-types/builtin/v16/market" + adt16 "github.com/filecoin-project/go-state-types/builtin/v16/util/adt" + markettypes "github.com/filecoin-project/go-state-types/builtin/v9/market" + + "github.com/filecoin-project/go-state-types/builtin" +) + +var _ State = (*state16)(nil) + +func load16(store adt.Store, root cid.Cid) (State, error) { + out := state16{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +func make16(store adt.Store) (State, error) { + out := state16{store: store} + + s, err := market16.ConstructState(store) + if err != nil { + return nil, err + } + + out.State = *s + + return &out, nil +} + +type state16 struct { + market16.State + store adt.Store +} + +func (s *state16) TotalLocked() (abi.TokenAmount, error) { + fml := types.BigAdd(s.TotalClientLockedCollateral, s.TotalProviderLockedCollateral) + fml = types.BigAdd(fml, s.TotalClientStorageFee) + return fml, nil +} + +func (s *state16) BalancesChanged(otherState State) (bool, error) { + otherState16, ok := otherState.(*state16) + 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(otherState16.State.EscrowTable) || !s.State.LockedTable.Equals(otherState16.State.LockedTable), nil +} + +func (s *state16) StatesChanged(otherState State) (bool, error) { + otherState16, ok := otherState.(*state16) + 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(otherState16.State.States), nil +} + +func (s *state16) States() (DealStates, error) { + stateArray, err := adt16.AsArray(s.store, s.State.States, market16.StatesAmtBitwidth) + if err != nil { + return nil, err + } + return &dealStates16{stateArray}, nil +} + +func (s *state16) ProposalsChanged(otherState State) (bool, error) { + otherState16, ok := otherState.(*state16) + 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(otherState16.State.Proposals), nil +} + +func (s *state16) Proposals() (DealProposals, error) { + proposalArray, err := adt16.AsArray(s.store, s.State.Proposals, market16.ProposalsAmtBitwidth) + if err != nil { + return nil, err + } + return &dealProposals16{proposalArray}, nil +} + +func (s *state16) PendingProposals() (PendingProposals, error) { + proposalCidSet, err := adt16.AsSet(s.store, s.State.PendingProposals, builtin.DefaultHamtBitwidth) + if err != nil { + return nil, err + } + return &pendingProposals16{proposalCidSet}, nil +} + +func (s *state16) EscrowTable() (BalanceTable, error) { + bt, err := adt16.AsBalanceTable(s.store, s.State.EscrowTable) + if err != nil { + return nil, err + } + return &balanceTable16{bt}, nil +} + +func (s *state16) LockedTable() (BalanceTable, error) { + bt, err := adt16.AsBalanceTable(s.store, s.State.LockedTable) + if err != nil { + return nil, err + } + return &balanceTable16{bt}, nil +} + +func (s *state16) VerifyDealsForActivation( + minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch, +) (verifiedWeight abi.DealWeight, err error) { + _, vw, _, err := market16.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) + return vw, err +} + +func (s *state16) NextID() (abi.DealID, error) { + return s.State.NextID, nil +} + +type balanceTable16 struct { + *adt16.BalanceTable +} + +func (bt *balanceTable16) ForEach(cb func(address.Address, abi.TokenAmount) error) error { + asMap := (*adt16.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 dealStates16 struct { + adt.Array +} + +func (s *dealStates16) Get(dealID abi.DealID) (DealState, bool, error) { + var deal16 market16.DealState + found, err := s.Array.Get(uint64(dealID), &deal16) + if err != nil { + return nil, false, err + } + if !found { + return nil, false, nil + } + deal := fromV16DealState(deal16) + return deal, true, nil +} + +func (s *dealStates16) ForEach(cb func(dealID abi.DealID, ds DealState) error) error { + var ds16 market16.DealState + return s.Array.ForEach(&ds16, func(idx int64) error { + return cb(abi.DealID(idx), fromV16DealState(ds16)) + }) +} + +func (s *dealStates16) decode(val *cbg.Deferred) (DealState, error) { + var ds16 market16.DealState + if err := ds16.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { + return nil, err + } + ds := fromV16DealState(ds16) + return ds, nil +} + +func (s *dealStates16) array() adt.Array { + return s.Array +} + +type dealStateV16 struct { + ds16 market16.DealState +} + +func (d dealStateV16) SectorNumber() abi.SectorNumber { + + return d.ds16.SectorNumber + +} + +func (d dealStateV16) SectorStartEpoch() abi.ChainEpoch { + return d.ds16.SectorStartEpoch +} + +func (d dealStateV16) LastUpdatedEpoch() abi.ChainEpoch { + return d.ds16.LastUpdatedEpoch +} + +func (d dealStateV16) SlashEpoch() abi.ChainEpoch { + return d.ds16.SlashEpoch +} + +func (d dealStateV16) Equals(other DealState) bool { + if ov16, ok := other.(dealStateV16); ok { + return d.ds16 == ov16.ds16 + } + + if d.SectorStartEpoch() != other.SectorStartEpoch() { + return false + } + if d.LastUpdatedEpoch() != other.LastUpdatedEpoch() { + return false + } + if d.SlashEpoch() != other.SlashEpoch() { + return false + } + + return true +} + +var _ DealState = (*dealStateV16)(nil) + +func fromV16DealState(v16 market16.DealState) DealState { + return dealStateV16{v16} +} + +type dealProposals16 struct { + adt.Array +} + +func (s *dealProposals16) Get(dealID abi.DealID) (*DealProposal, bool, error) { + var proposal16 market16.DealProposal + found, err := s.Array.Get(uint64(dealID), &proposal16) + if err != nil { + return nil, false, err + } + if !found { + return nil, false, nil + } + + proposal, err := fromV16DealProposal(proposal16) + if err != nil { + return nil, true, fmt.Errorf("decoding proposal: %w", err) + } + + return &proposal, true, nil +} + +func (s *dealProposals16) ForEach(cb func(dealID abi.DealID, dp DealProposal) error) error { + var dp16 market16.DealProposal + return s.Array.ForEach(&dp16, func(idx int64) error { + dp, err := fromV16DealProposal(dp16) + if err != nil { + return fmt.Errorf("decoding proposal: %w", err) + } + + return cb(abi.DealID(idx), dp) + }) +} + +func (s *dealProposals16) decode(val *cbg.Deferred) (*DealProposal, error) { + var dp16 market16.DealProposal + if err := dp16.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { + return nil, err + } + + dp, err := fromV16DealProposal(dp16) + if err != nil { + return nil, err + } + + return &dp, nil +} + +func (s *dealProposals16) array() adt.Array { + return s.Array +} + +type pendingProposals16 struct { + *adt16.Set +} + +func (s *pendingProposals16) Has(proposalCid cid.Cid) (bool, error) { + return s.Set.Has(abi.CidKey(proposalCid)) +} + +func fromV16DealProposal(v16 market16.DealProposal) (DealProposal, error) { + + label, err := fromV16Label(v16.Label) + + if err != nil { + return DealProposal{}, fmt.Errorf("error setting deal label: %w", err) + } + + return DealProposal{ + PieceCID: v16.PieceCID, + PieceSize: v16.PieceSize, + VerifiedDeal: v16.VerifiedDeal, + Client: v16.Client, + Provider: v16.Provider, + + Label: label, + + StartEpoch: v16.StartEpoch, + EndEpoch: v16.EndEpoch, + StoragePricePerEpoch: v16.StoragePricePerEpoch, + + ProviderCollateral: v16.ProviderCollateral, + ClientCollateral: v16.ClientCollateral, + }, nil +} + +func fromV16Label(v16 market16.DealLabel) (DealLabel, error) { + if v16.IsString() { + str, err := v16.ToString() + if err != nil { + return markettypes.EmptyDealLabel, fmt.Errorf("failed to convert string label to string: %w", err) + } + return markettypes.NewLabelFromString(str) + } + + bs, err := v16.ToBytes() + if err != nil { + return markettypes.EmptyDealLabel, fmt.Errorf("failed to convert bytes label to bytes: %w", err) + } + return markettypes.NewLabelFromBytes(bs) +} + +func (s *state16) GetState() interface{} { + return &s.State +} + +var _ PublishStorageDealsReturn = (*publishStorageDealsReturn16)(nil) + +func decodePublishStorageDealsReturn16(b []byte) (PublishStorageDealsReturn, error) { + var retval market16.PublishStorageDealsReturn + if err := retval.UnmarshalCBOR(bytes.NewReader(b)); err != nil { + return nil, fmt.Errorf("failed to unmarshal PublishStorageDealsReturn: %w", err) + } + + return &publishStorageDealsReturn16{retval}, nil +} + +type publishStorageDealsReturn16 struct { + market16.PublishStorageDealsReturn +} + +func (r *publishStorageDealsReturn16) IsDealValid(index uint64) (bool, int, error) { + + set, err := r.ValidDeals.IsSet(index) + if err != nil || !set { + return false, -1, err + } + maskBf, err := bitfield.NewFromIter(&rlepluslazy.RunSliceIterator{ + Runs: []rlepluslazy.Run{rlepluslazy.Run{Val: true, Len: index}}}) + if err != nil { + return false, -1, err + } + before, err := bitfield.IntersectBitField(maskBf, r.ValidDeals) + if err != nil { + return false, -1, err + } + outIdx, err := before.Count() + if err != nil { + return false, -1, err + } + return set, int(outIdx), nil + +} + +func (r *publishStorageDealsReturn16) DealIDs() ([]abi.DealID, error) { + return r.IDs, nil +} + +func (s *state16) GetAllocationIdForPendingDeal(dealId abi.DealID) (verifregtypes.AllocationId, error) { + + allocations, err := adt16.AsMap(s.store, s.PendingDealAllocationIds, builtin.DefaultHamtBitwidth) + if err != nil { + return verifregtypes.NoAllocationID, fmt.Errorf("failed to load allocation id for %d: %w", dealId, err) + } + + var allocationId cbg.CborInt + found, err := allocations.Get(abi.UIntKey(uint64(dealId)), &allocationId) + if err != nil { + return verifregtypes.NoAllocationID, fmt.Errorf("failed to load allocation id for %d: %w", dealId, err) + } + if !found { + return verifregtypes.NoAllocationID, nil + } + + return verifregtypes.AllocationId(allocationId), nil + +} + +func (s *state16) ActorKey() string { + return manifest.MarketKey +} + +func (s *state16) ActorVersion() actorstypes.Version { + return actorstypes.Version16 +} + +func (s *state16) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/venus-shared/actors/builtin/market/state.v2.go b/venus-shared/actors/builtin/market/state.v2.go index 6a76643767..15ab46106f 100644 --- a/venus-shared/actors/builtin/market/state.v2.go +++ b/venus-shared/actors/builtin/market/state.v2.go @@ -108,6 +108,14 @@ func (s *state2) Proposals() (DealProposals, error) { return &dealProposals2{proposalArray}, nil } +func (s *state2) PendingProposals() (PendingProposals, error) { + proposalCidSet, err := adt2.AsSet(s.store, s.State.PendingProposals) + if err != nil { + return nil, err + } + return &pendingProposals2{proposalCidSet}, nil +} + func (s *state2) EscrowTable() (BalanceTable, error) { bt, err := adt2.AsBalanceTable(s.store, s.State.EscrowTable) if err != nil { @@ -126,9 +134,9 @@ func (s *state2) LockedTable() (BalanceTable, error) { func (s *state2) VerifyDealsForActivation( minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch, -) (weight, verifiedWeight abi.DealWeight, err error) { - w, vw, _, err := market2.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) - return w, vw, err +) (verifiedWeight abi.DealWeight, err error) { + _, vw, _, err := market2.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) + return vw, err } func (s *state2) NextID() (abi.DealID, error) { @@ -286,6 +294,14 @@ func (s *dealProposals2) array() adt.Array { return s.Array } +type pendingProposals2 struct { + *adt2.Set +} + +func (s *pendingProposals2) Has(proposalCid cid.Cid) (bool, error) { + return s.Set.Has(abi.CidKey(proposalCid)) +} + func fromV2DealProposal(v2 market2.DealProposal) (DealProposal, error) { label, err := labelFromGoString(v2.Label) diff --git a/venus-shared/actors/builtin/market/state.v3.go b/venus-shared/actors/builtin/market/state.v3.go index 54f0d0b3c0..513cd01044 100644 --- a/venus-shared/actors/builtin/market/state.v3.go +++ b/venus-shared/actors/builtin/market/state.v3.go @@ -20,6 +20,8 @@ import ( market3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/market" adt3 "github.com/filecoin-project/specs-actors/v3/actors/util/adt" + + "github.com/filecoin-project/go-state-types/builtin" ) var _ State = (*state3)(nil) @@ -103,6 +105,14 @@ func (s *state3) Proposals() (DealProposals, error) { return &dealProposals3{proposalArray}, nil } +func (s *state3) PendingProposals() (PendingProposals, error) { + proposalCidSet, err := adt3.AsSet(s.store, s.State.PendingProposals, builtin.DefaultHamtBitwidth) + if err != nil { + return nil, err + } + return &pendingProposals3{proposalCidSet}, nil +} + func (s *state3) EscrowTable() (BalanceTable, error) { bt, err := adt3.AsBalanceTable(s.store, s.State.EscrowTable) if err != nil { @@ -121,9 +131,9 @@ func (s *state3) LockedTable() (BalanceTable, error) { 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 +) (verifiedWeight abi.DealWeight, err error) { + _, vw, _, err := market3.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) + return vw, err } func (s *state3) NextID() (abi.DealID, error) { @@ -281,6 +291,14 @@ func (s *dealProposals3) array() adt.Array { return s.Array } +type pendingProposals3 struct { + *adt3.Set +} + +func (s *pendingProposals3) Has(proposalCid cid.Cid) (bool, error) { + return s.Set.Has(abi.CidKey(proposalCid)) +} + func fromV3DealProposal(v3 market3.DealProposal) (DealProposal, error) { label, err := labelFromGoString(v3.Label) diff --git a/venus-shared/actors/builtin/market/state.v4.go b/venus-shared/actors/builtin/market/state.v4.go index 64287434b2..0afe620cea 100644 --- a/venus-shared/actors/builtin/market/state.v4.go +++ b/venus-shared/actors/builtin/market/state.v4.go @@ -20,6 +20,8 @@ import ( market4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/market" adt4 "github.com/filecoin-project/specs-actors/v4/actors/util/adt" + + "github.com/filecoin-project/go-state-types/builtin" ) var _ State = (*state4)(nil) @@ -103,6 +105,14 @@ func (s *state4) Proposals() (DealProposals, error) { return &dealProposals4{proposalArray}, nil } +func (s *state4) PendingProposals() (PendingProposals, error) { + proposalCidSet, err := adt4.AsSet(s.store, s.State.PendingProposals, builtin.DefaultHamtBitwidth) + if err != nil { + return nil, err + } + return &pendingProposals4{proposalCidSet}, nil +} + func (s *state4) EscrowTable() (BalanceTable, error) { bt, err := adt4.AsBalanceTable(s.store, s.State.EscrowTable) if err != nil { @@ -121,9 +131,9 @@ func (s *state4) LockedTable() (BalanceTable, error) { func (s *state4) VerifyDealsForActivation( minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch, -) (weight, verifiedWeight abi.DealWeight, err error) { - w, vw, _, err := market4.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) - return w, vw, err +) (verifiedWeight abi.DealWeight, err error) { + _, vw, _, err := market4.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) + return vw, err } func (s *state4) NextID() (abi.DealID, error) { @@ -281,6 +291,14 @@ func (s *dealProposals4) array() adt.Array { return s.Array } +type pendingProposals4 struct { + *adt4.Set +} + +func (s *pendingProposals4) Has(proposalCid cid.Cid) (bool, error) { + return s.Set.Has(abi.CidKey(proposalCid)) +} + func fromV4DealProposal(v4 market4.DealProposal) (DealProposal, error) { label, err := labelFromGoString(v4.Label) diff --git a/venus-shared/actors/builtin/market/state.v5.go b/venus-shared/actors/builtin/market/state.v5.go index 4d1e00fda3..21add3d885 100644 --- a/venus-shared/actors/builtin/market/state.v5.go +++ b/venus-shared/actors/builtin/market/state.v5.go @@ -20,6 +20,8 @@ import ( market5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/market" adt5 "github.com/filecoin-project/specs-actors/v5/actors/util/adt" + + "github.com/filecoin-project/go-state-types/builtin" ) var _ State = (*state5)(nil) @@ -103,6 +105,14 @@ func (s *state5) Proposals() (DealProposals, error) { return &dealProposals5{proposalArray}, nil } +func (s *state5) PendingProposals() (PendingProposals, error) { + proposalCidSet, err := adt5.AsSet(s.store, s.State.PendingProposals, builtin.DefaultHamtBitwidth) + if err != nil { + return nil, err + } + return &pendingProposals5{proposalCidSet}, nil +} + func (s *state5) EscrowTable() (BalanceTable, error) { bt, err := adt5.AsBalanceTable(s.store, s.State.EscrowTable) if err != nil { @@ -121,9 +131,9 @@ func (s *state5) LockedTable() (BalanceTable, error) { func (s *state5) VerifyDealsForActivation( minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch, -) (weight, verifiedWeight abi.DealWeight, err error) { - w, vw, _, err := market5.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) - return w, vw, err +) (verifiedWeight abi.DealWeight, err error) { + _, vw, _, err := market5.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) + return vw, err } func (s *state5) NextID() (abi.DealID, error) { @@ -281,6 +291,14 @@ func (s *dealProposals5) array() adt.Array { return s.Array } +type pendingProposals5 struct { + *adt5.Set +} + +func (s *pendingProposals5) Has(proposalCid cid.Cid) (bool, error) { + return s.Set.Has(abi.CidKey(proposalCid)) +} + func fromV5DealProposal(v5 market5.DealProposal) (DealProposal, error) { label, err := labelFromGoString(v5.Label) diff --git a/venus-shared/actors/builtin/market/state.v6.go b/venus-shared/actors/builtin/market/state.v6.go index 4812c1375f..9343c1d875 100644 --- a/venus-shared/actors/builtin/market/state.v6.go +++ b/venus-shared/actors/builtin/market/state.v6.go @@ -23,6 +23,8 @@ import ( market6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/market" adt6 "github.com/filecoin-project/specs-actors/v6/actors/util/adt" + + "github.com/filecoin-project/go-state-types/builtin" ) var _ State = (*state6)(nil) @@ -106,6 +108,14 @@ func (s *state6) Proposals() (DealProposals, error) { return &dealProposals6{proposalArray}, nil } +func (s *state6) PendingProposals() (PendingProposals, error) { + proposalCidSet, err := adt6.AsSet(s.store, s.State.PendingProposals, builtin.DefaultHamtBitwidth) + if err != nil { + return nil, err + } + return &pendingProposals6{proposalCidSet}, nil +} + func (s *state6) EscrowTable() (BalanceTable, error) { bt, err := adt6.AsBalanceTable(s.store, s.State.EscrowTable) if err != nil { @@ -124,9 +134,9 @@ func (s *state6) LockedTable() (BalanceTable, error) { func (s *state6) VerifyDealsForActivation( minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch, -) (weight, verifiedWeight abi.DealWeight, err error) { - w, vw, _, err := market6.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) - return w, vw, err +) (verifiedWeight abi.DealWeight, err error) { + _, vw, _, err := market6.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) + return vw, err } func (s *state6) NextID() (abi.DealID, error) { @@ -284,6 +294,14 @@ func (s *dealProposals6) array() adt.Array { return s.Array } +type pendingProposals6 struct { + *adt6.Set +} + +func (s *pendingProposals6) Has(proposalCid cid.Cid) (bool, error) { + return s.Set.Has(abi.CidKey(proposalCid)) +} + func fromV6DealProposal(v6 market6.DealProposal) (DealProposal, error) { label, err := labelFromGoString(v6.Label) diff --git a/venus-shared/actors/builtin/market/state.v7.go b/venus-shared/actors/builtin/market/state.v7.go index a0233eac79..bf2b83cda7 100644 --- a/venus-shared/actors/builtin/market/state.v7.go +++ b/venus-shared/actors/builtin/market/state.v7.go @@ -23,6 +23,8 @@ import ( market7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/market" adt7 "github.com/filecoin-project/specs-actors/v7/actors/util/adt" + + "github.com/filecoin-project/go-state-types/builtin" ) var _ State = (*state7)(nil) @@ -106,6 +108,14 @@ func (s *state7) Proposals() (DealProposals, error) { return &dealProposals7{proposalArray}, nil } +func (s *state7) PendingProposals() (PendingProposals, error) { + proposalCidSet, err := adt7.AsSet(s.store, s.State.PendingProposals, builtin.DefaultHamtBitwidth) + if err != nil { + return nil, err + } + return &pendingProposals7{proposalCidSet}, nil +} + func (s *state7) EscrowTable() (BalanceTable, error) { bt, err := adt7.AsBalanceTable(s.store, s.State.EscrowTable) if err != nil { @@ -124,9 +134,9 @@ func (s *state7) LockedTable() (BalanceTable, error) { func (s *state7) VerifyDealsForActivation( minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch, -) (weight, verifiedWeight abi.DealWeight, err error) { - w, vw, _, err := market7.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) - return w, vw, err +) (verifiedWeight abi.DealWeight, err error) { + _, vw, _, err := market7.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) + return vw, err } func (s *state7) NextID() (abi.DealID, error) { @@ -284,6 +294,14 @@ func (s *dealProposals7) array() adt.Array { return s.Array } +type pendingProposals7 struct { + *adt7.Set +} + +func (s *pendingProposals7) Has(proposalCid cid.Cid) (bool, error) { + return s.Set.Has(abi.CidKey(proposalCid)) +} + func fromV7DealProposal(v7 market7.DealProposal) (DealProposal, error) { label, err := labelFromGoString(v7.Label) diff --git a/venus-shared/actors/builtin/market/state.v8.go b/venus-shared/actors/builtin/market/state.v8.go index cbf7db90bb..a6c19c8bb8 100644 --- a/venus-shared/actors/builtin/market/state.v8.go +++ b/venus-shared/actors/builtin/market/state.v8.go @@ -24,6 +24,8 @@ import ( market8 "github.com/filecoin-project/go-state-types/builtin/v8/market" adt8 "github.com/filecoin-project/go-state-types/builtin/v8/util/adt" markettypes "github.com/filecoin-project/go-state-types/builtin/v9/market" + + "github.com/filecoin-project/go-state-types/builtin" ) var _ State = (*state8)(nil) @@ -107,6 +109,14 @@ func (s *state8) Proposals() (DealProposals, error) { return &dealProposals8{proposalArray}, nil } +func (s *state8) PendingProposals() (PendingProposals, error) { + proposalCidSet, err := adt8.AsSet(s.store, s.State.PendingProposals, builtin.DefaultHamtBitwidth) + if err != nil { + return nil, err + } + return &pendingProposals8{proposalCidSet}, nil +} + func (s *state8) EscrowTable() (BalanceTable, error) { bt, err := adt8.AsBalanceTable(s.store, s.State.EscrowTable) if err != nil { @@ -125,9 +135,9 @@ func (s *state8) LockedTable() (BalanceTable, error) { func (s *state8) VerifyDealsForActivation( minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch, -) (weight, verifiedWeight abi.DealWeight, err error) { - w, vw, _, err := market8.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) - return w, vw, err +) (verifiedWeight abi.DealWeight, err error) { + _, vw, _, err := market8.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) + return vw, err } func (s *state8) NextID() (abi.DealID, error) { @@ -285,6 +295,14 @@ func (s *dealProposals8) array() adt.Array { return s.Array } +type pendingProposals8 struct { + *adt8.Set +} + +func (s *pendingProposals8) Has(proposalCid cid.Cid) (bool, error) { + return s.Set.Has(abi.CidKey(proposalCid)) +} + func fromV8DealProposal(v8 market8.DealProposal) (DealProposal, error) { label, err := fromV8Label(v8.Label) diff --git a/venus-shared/actors/builtin/market/state.v9.go b/venus-shared/actors/builtin/market/state.v9.go index 9ff0aa2726..39aa175e54 100644 --- a/venus-shared/actors/builtin/market/state.v9.go +++ b/venus-shared/actors/builtin/market/state.v9.go @@ -109,6 +109,14 @@ func (s *state9) Proposals() (DealProposals, error) { return &dealProposals9{proposalArray}, nil } +func (s *state9) PendingProposals() (PendingProposals, error) { + proposalCidSet, err := adt9.AsSet(s.store, s.State.PendingProposals, builtin.DefaultHamtBitwidth) + if err != nil { + return nil, err + } + return &pendingProposals9{proposalCidSet}, nil +} + func (s *state9) EscrowTable() (BalanceTable, error) { bt, err := adt9.AsBalanceTable(s.store, s.State.EscrowTable) if err != nil { @@ -127,9 +135,9 @@ func (s *state9) LockedTable() (BalanceTable, error) { func (s *state9) VerifyDealsForActivation( minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch, -) (weight, verifiedWeight abi.DealWeight, err error) { - w, vw, _, err := market9.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) - return w, vw, err +) (verifiedWeight abi.DealWeight, err error) { + _, vw, _, err := market9.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) + return vw, err } func (s *state9) NextID() (abi.DealID, error) { @@ -287,6 +295,14 @@ func (s *dealProposals9) array() adt.Array { return s.Array } +type pendingProposals9 struct { + *adt9.Set +} + +func (s *pendingProposals9) Has(proposalCid cid.Cid) (bool, error) { + return s.Set.Has(abi.CidKey(proposalCid)) +} + func fromV9DealProposal(v9 market9.DealProposal) (DealProposal, error) { label, err := fromV9Label(v9.Label) diff --git a/venus-shared/actors/builtin/miner/actor.go b/venus-shared/actors/builtin/miner/actor.go index 6f5c50ba93..984c74ebb7 100644 --- a/venus-shared/actors/builtin/miner/actor.go +++ b/venus-shared/actors/builtin/miner/actor.go @@ -71,6 +71,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) { case actorstypes.Version15: return load15(store, act.Head) + case actorstypes.Version16: + return load16(store, act.Head) + } } @@ -150,6 +153,9 @@ func MakeState(store adt.Store, av actors.Version) (State, error) { case actors.Version15: return make15(store) + case actors.Version16: + return make16(store) + } return nil, fmt.Errorf("unknown actor version %d", av) } @@ -416,5 +422,6 @@ func AllCodes() []cid.Cid { (&state13{}).Code(), (&state14{}).Code(), (&state15{}).Code(), + (&state16{}).Code(), } } diff --git a/venus-shared/actors/builtin/miner/state.v16.go b/venus-shared/actors/builtin/miner/state.v16.go new file mode 100644 index 0000000000..17631b0eba --- /dev/null +++ b/venus-shared/actors/builtin/miner/state.v16.go @@ -0,0 +1,596 @@ +// FETCHED FROM LOTUS: builtin/miner/state.go.template + +package miner + +import ( + "bytes" + "errors" + "fmt" + + "github.com/filecoin-project/go-bitfield" + rle "github.com/filecoin-project/go-bitfield/rle" + "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/go-state-types/dline" + "github.com/ipfs/go-cid" + cbg "github.com/whyrusleeping/cbor-gen" + + actorstypes "github.com/filecoin-project/go-state-types/actors" + "github.com/filecoin-project/go-state-types/manifest" + "github.com/filecoin-project/venus/venus-shared/actors" + "github.com/filecoin-project/venus/venus-shared/actors/adt" + + builtin16 "github.com/filecoin-project/go-state-types/builtin" + miner16 "github.com/filecoin-project/go-state-types/builtin/v16/miner" + adt16 "github.com/filecoin-project/go-state-types/builtin/v16/util/adt" +) + +var _ State = (*state16)(nil) + +func load16(store adt.Store, root cid.Cid) (State, error) { + out := state16{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +func make16(store adt.Store) (State, error) { + out := state16{store: store} + out.State = miner16.State{} + return &out, nil +} + +type state16 struct { + miner16.State + store adt.Store +} + +type deadline16 struct { + miner16.Deadline + store adt.Store +} + +type partition16 struct { + miner16.Partition + store adt.Store +} + +func (s *state16) AvailableBalance(bal abi.TokenAmount) (available abi.TokenAmount, err error) { + defer func() { + if r := recover(); r != nil { + err = fmt.Errorf("failed to get available balance: %v", r) + available = abi.NewTokenAmount(0) + } + }() + // this panics if the miner doesn't have enough funds to cover their locked pledge + available, err = s.GetAvailableBalance(bal) + return available, err +} + +func (s *state16) VestedFunds(epoch abi.ChainEpoch) (abi.TokenAmount, error) { + return s.CheckVestedFunds(s.store, epoch) +} + +func (s *state16) LockedFunds() (LockedFunds, error) { + return LockedFunds{ + VestingFunds: s.State.LockedFunds, + InitialPledgeRequirement: s.State.InitialPledge, + PreCommitDeposits: s.State.PreCommitDeposits, + }, nil +} + +func (s *state16) FeeDebt() (abi.TokenAmount, error) { + return s.State.FeeDebt, nil +} + +func (s *state16) InitialPledge() (abi.TokenAmount, error) { + return s.State.InitialPledge, nil +} + +func (s *state16) PreCommitDeposits() (abi.TokenAmount, error) { + return s.State.PreCommitDeposits, nil +} + +// Returns nil, nil if sector is not found +func (s *state16) GetSector(num abi.SectorNumber) (*SectorOnChainInfo, error) { + info, ok, err := s.State.GetSector(s.store, num) + if !ok || err != nil { + return nil, err + } + + ret := fromV16SectorOnChainInfo(*info) + return &ret, nil +} + +func (s *state16) 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 *state16) 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 *miner16.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 *state16) 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 expire on-time (can be + // learned from the sector info). + // 2. If it's faulty, it will expire early within the first 42 entries + // of the expiration queue. + + stopErr := errors.New("stop") + out := SectorExpiration{} + err = dls.ForEach(s.store, func(dlIdx uint64, dl *miner16.Deadline) error { + partitions, err := dl.PartitionsArray(s.store) + if err != nil { + return err + } + quant := s.State.QuantSpecForDeadline(dlIdx) + var part miner16.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 := miner16.LoadExpirationQueue(s.store, part.ExpirationsEpochs, quant, miner16.PartitionExpirationAmtBitwidth) + if err != nil { + return err + } + var exp miner16.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, fmt.Errorf("failed to find sector %d", num) + } + return &out, nil +} + +func (s *state16) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitOnChainInfo, error) { + info, ok, err := s.State.GetPrecommittedSector(s.store, num) + if !ok || err != nil { + return nil, err + } + + ret := fromV16SectorPreCommitOnChainInfo(*info) + + return &ret, nil +} + +func (s *state16) ForEachPrecommittedSector(cb func(SectorPreCommitOnChainInfo) error) error { + precommitted, err := adt16.AsMap(s.store, s.State.PreCommittedSectors, builtin16.DefaultHamtBitwidth) + if err != nil { + return err + } + + var info miner16.SectorPreCommitOnChainInfo + if err := precommitted.ForEach(&info, func(_ string) error { + return cb(fromV16SectorPreCommitOnChainInfo(info)) + }); err != nil { + return err + } + + return nil +} + +func (s *state16) LoadSectors(snos *bitfield.BitField) ([]*SectorOnChainInfo, error) { + sectors, err := miner16.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 info16 miner16.SectorOnChainInfo + if err := sectors.ForEach(&info16, func(_ int64) error { + info := fromV16SectorOnChainInfo(info16) + infos = append(infos, &info) + return nil + }); err != nil { + return nil, err + } + return infos, nil + } + + // Otherwise, load selected. + infos16, err := sectors.Load(*snos) + if err != nil { + return nil, err + } + infos := make([]*SectorOnChainInfo, len(infos16)) + for i, info16 := range infos16 { + info := fromV16SectorOnChainInfo(*info16) + infos[i] = &info + } + return infos, nil +} + +func (s *state16) loadAllocatedSectorNumbers() (bitfield.BitField, error) { + var allocatedSectors bitfield.BitField + err := s.store.Get(s.store.Context(), s.State.AllocatedSectors, &allocatedSectors) + return allocatedSectors, err +} + +func (s *state16) IsAllocated(num abi.SectorNumber) (bool, error) { + allocatedSectors, err := s.loadAllocatedSectorNumbers() + if err != nil { + return false, err + } + + return allocatedSectors.IsSet(uint64(num)) +} + +func (s *state16) GetProvingPeriodStart() (abi.ChainEpoch, error) { + return s.State.ProvingPeriodStart, nil +} + +func (s *state16) UnallocatedSectorNumbers(count int) ([]abi.SectorNumber, error) { + allocatedSectors, err := s.loadAllocatedSectorNumbers() + if err != nil { + return nil, err + } + + allocatedRuns, err := allocatedSectors.RunIterator() + if err != nil { + return nil, err + } + + unallocatedRuns, err := rle.Subtract( + &rle.RunSliceIterator{Runs: []rle.Run{{Val: true, Len: abi.MaxSectorNumber}}}, + allocatedRuns, + ) + if err != nil { + return nil, err + } + + iter, err := rle.BitsFromRuns(unallocatedRuns) + if err != nil { + return nil, err + } + + sectors := make([]abi.SectorNumber, 0, count) + for iter.HasNext() && len(sectors) < count { + nextNo, err := iter.Next() + if err != nil { + return nil, err + } + sectors = append(sectors, abi.SectorNumber(nextNo)) + } + + return sectors, nil +} + +func (s *state16) GetAllocatedSectors() (*bitfield.BitField, error) { + var allocatedSectors bitfield.BitField + if err := s.store.Get(s.store.Context(), s.State.AllocatedSectors, &allocatedSectors); err != nil { + return nil, err + } + + return &allocatedSectors, nil +} + +func (s *state16) 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 &deadline16{*dl, s.store}, nil +} + +func (s *state16) 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 *miner16.Deadline) error { + return cb(i, &deadline16{*dl, s.store}) + }) +} + +func (s *state16) NumDeadlines() (uint64, error) { + return miner16.WPoStPeriodDeadlines, nil +} + +func (s *state16) DeadlinesChanged(other State) (bool, error) { + other16, ok := other.(*state16) + if !ok { + // treat an upgrade as a change, always + return true, nil + } + + return !s.State.Deadlines.Equals(other16.Deadlines), nil +} + +func (s *state16) MinerInfoChanged(other State) (bool, error) { + other0, ok := other.(*state16) + if !ok { + // treat an upgrade as a change, always + return true, nil + } + return !s.State.Info.Equals(other0.State.Info), nil +} + +func (s *state16) Info() (MinerInfo, error) { + info, err := s.State.GetInfo(s.store) + if err != nil { + return MinerInfo{}, err + } + + mi := MinerInfo{ + Owner: info.Owner, + Worker: info.Worker, + ControlAddresses: info.ControlAddresses, + + PendingWorkerKey: (*WorkerKeyChange)(info.PendingWorkerKey), + + PeerId: info.PeerId, + Multiaddrs: info.Multiaddrs, + WindowPoStProofType: info.WindowPoStProofType, + SectorSize: info.SectorSize, + WindowPoStPartitionSectors: info.WindowPoStPartitionSectors, + ConsensusFaultElapsed: info.ConsensusFaultElapsed, + + Beneficiary: info.Beneficiary, + BeneficiaryTerm: BeneficiaryTerm(info.BeneficiaryTerm), + PendingBeneficiaryTerm: (*PendingBeneficiaryChange)(info.PendingBeneficiaryTerm), + } + + return mi, nil +} + +func (s *state16) DeadlineInfo(epoch abi.ChainEpoch) (*dline.Info, error) { + return s.State.RecordedDeadlineInfo(epoch), nil +} + +func (s *state16) DeadlineCronActive() (bool, error) { + return s.State.DeadlineCronActive, nil +} + +func (s *state16) sectors() (adt.Array, error) { + return adt16.AsArray(s.store, s.Sectors, miner16.SectorsAmtBitwidth) +} + +func (s *state16) decodeSectorOnChainInfo(val *cbg.Deferred) (SectorOnChainInfo, error) { + var si miner16.SectorOnChainInfo + err := si.UnmarshalCBOR(bytes.NewReader(val.Raw)) + if err != nil { + return SectorOnChainInfo{}, err + } + + return fromV16SectorOnChainInfo(si), nil +} + +func (s *state16) precommits() (adt.Map, error) { + return adt16.AsMap(s.store, s.PreCommittedSectors, builtin16.DefaultHamtBitwidth) +} + +func (s *state16) decodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (SectorPreCommitOnChainInfo, error) { + var sp miner16.SectorPreCommitOnChainInfo + err := sp.UnmarshalCBOR(bytes.NewReader(val.Raw)) + if err != nil { + return SectorPreCommitOnChainInfo{}, err + } + + return fromV16SectorPreCommitOnChainInfo(sp), nil +} + +func (s *state16) EraseAllUnproven() error { + + dls, err := s.State.LoadDeadlines(s.store) + if err != nil { + return err + } + + err = dls.ForEach(s.store, func(dindx uint64, dl *miner16.Deadline) error { + ps, err := dl.PartitionsArray(s.store) + if err != nil { + return err + } + + var part miner16.Partition + err = ps.ForEach(&part, func(pindx int64) error { + _ = part.ActivateUnproven() + err = ps.Set(uint64(pindx), &part) + return nil + }) + + if err != nil { + return err + } + + dl.Partitions, err = ps.Root() + if err != nil { + return err + } + + return dls.UpdateDeadline(s.store, dindx, dl) + }) + if err != nil { + return err + } + + return s.State.SaveDeadlines(s.store, dls) + +} + +func (d *deadline16) LoadPartition(idx uint64) (Partition, error) { + p, err := d.Deadline.LoadPartition(d.store, idx) + if err != nil { + return nil, err + } + return &partition16{*p, d.store}, nil +} + +func (d *deadline16) ForEachPartition(cb func(uint64, Partition) error) error { + ps, err := d.Deadline.PartitionsArray(d.store) + if err != nil { + return err + } + var part miner16.Partition + return ps.ForEach(&part, func(i int64) error { + return cb(uint64(i), &partition16{part, d.store}) + }) +} + +func (d *deadline16) PartitionsChanged(other Deadline) (bool, error) { + other16, ok := other.(*deadline16) + if !ok { + // treat an upgrade as a change, always + return true, nil + } + + return !d.Deadline.Partitions.Equals(other16.Deadline.Partitions), nil +} + +func (d *deadline16) PartitionsPoSted() (bitfield.BitField, error) { + return d.Deadline.PartitionsPoSted, nil +} + +func (d *deadline16) DisputableProofCount() (uint64, error) { + + ops, err := d.OptimisticProofsSnapshotArray(d.store) + if err != nil { + return 0, err + } + + return ops.Length(), nil + +} + +func (p *partition16) AllSectors() (bitfield.BitField, error) { + return p.Partition.Sectors, nil +} + +func (p *partition16) FaultySectors() (bitfield.BitField, error) { + return p.Partition.Faults, nil +} + +func (p *partition16) RecoveringSectors() (bitfield.BitField, error) { + return p.Partition.Recoveries, nil +} + +func (p *partition16) UnprovenSectors() (bitfield.BitField, error) { + return p.Partition.Unproven, nil +} + +func fromV16SectorOnChainInfo(v16 miner16.SectorOnChainInfo) SectorOnChainInfo { + info := SectorOnChainInfo{ + SectorNumber: v16.SectorNumber, + SealProof: v16.SealProof, + SealedCID: v16.SealedCID, + DealIDs: v16.DealIDs, + Activation: v16.Activation, + Expiration: v16.Expiration, + DealWeight: v16.DealWeight, + VerifiedDealWeight: v16.VerifiedDealWeight, + InitialPledge: v16.InitialPledge, + ExpectedDayReward: v16.ExpectedDayReward, + ExpectedStoragePledge: v16.ExpectedStoragePledge, + + SectorKeyCID: v16.SectorKeyCID, + + PowerBaseEpoch: v16.PowerBaseEpoch, + ReplacedDayReward: v16.ReplacedDayReward, + Flags: SectorOnChainInfoFlags(v16.Flags), + } + return info +} + +func fromV16SectorPreCommitOnChainInfo(v16 miner16.SectorPreCommitOnChainInfo) SectorPreCommitOnChainInfo { + ret := SectorPreCommitOnChainInfo{ + Info: SectorPreCommitInfo{ + SealProof: v16.Info.SealProof, + SectorNumber: v16.Info.SectorNumber, + SealedCID: v16.Info.SealedCID, + SealRandEpoch: v16.Info.SealRandEpoch, + DealIDs: v16.Info.DealIDs, + Expiration: v16.Info.Expiration, + UnsealedCid: nil, + }, + PreCommitDeposit: v16.PreCommitDeposit, + PreCommitEpoch: v16.PreCommitEpoch, + } + + ret.Info.UnsealedCid = v16.Info.UnsealedCid + + return ret +} + +func (s *state16) GetState() interface{} { + return &s.State +} + +func (s *state16) ActorKey() string { + return manifest.MinerKey +} + +func (s *state16) ActorVersion() actorstypes.Version { + return actorstypes.Version16 +} + +func (s *state16) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/venus-shared/actors/builtin/multisig/actor.go b/venus-shared/actors/builtin/multisig/actor.go index 7faa742bf6..9a3d0bb67c 100644 --- a/venus-shared/actors/builtin/multisig/actor.go +++ b/venus-shared/actors/builtin/multisig/actor.go @@ -15,7 +15,7 @@ import ( "github.com/filecoin-project/go-state-types/cbor" "github.com/filecoin-project/go-state-types/manifest" - msig15 "github.com/filecoin-project/go-state-types/builtin/v15/multisig" + msig16 "github.com/filecoin-project/go-state-types/builtin/v16/multisig" builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" @@ -68,6 +68,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) { case actorstypes.Version15: return load15(store, act.Head) + case actorstypes.Version16: + return load16(store, act.Head) + } } @@ -147,6 +150,9 @@ func MakeState(store adt.Store, av actorstypes.Version, signers []address.Addres case actorstypes.Version15: return make15(store, signers, threshold, startEpoch, unlockDuration, initialBalance) + case actorstypes.Version16: + return make16(store, signers, threshold, startEpoch, unlockDuration, initialBalance) + } return nil, fmt.Errorf("unknown actor version %d", av) } @@ -173,7 +179,7 @@ type State interface { GetState() interface{} } -type Transaction = msig15.Transaction +type Transaction = msig16.Transaction var Methods = builtintypes.MethodsMultisig @@ -224,6 +230,9 @@ func Message(version actorstypes.Version, from address.Address) MessageBuilder { case actorstypes.Version15: return message15{message0{from}} + + case actorstypes.Version16: + return message16{message0{from}} default: panic(fmt.Sprintf("unsupported actors version: %d", version)) } @@ -247,10 +256,10 @@ type MessageBuilder interface { } // this type is the same between v0 and v2 -type ProposalHashData = msig15.ProposalHashData -type ProposeReturn = msig15.ProposeReturn -type ProposeParams = msig15.ProposeParams -type ApproveReturn = msig15.ApproveReturn +type ProposalHashData = msig16.ProposalHashData +type ProposeReturn = msig16.ProposeReturn +type ProposeParams = msig16.ProposeParams +type ApproveReturn = msig16.ApproveReturn func AllCodes() []cid.Cid { return []cid.Cid{ @@ -269,5 +278,6 @@ func AllCodes() []cid.Cid { (&state13{}).Code(), (&state14{}).Code(), (&state15{}).Code(), + (&state16{}).Code(), } } diff --git a/venus-shared/actors/builtin/multisig/message.v10.go b/venus-shared/actors/builtin/multisig/message.v10.go index fe3f3184d9..41076e0ff8 100644 --- a/venus-shared/actors/builtin/multisig/message.v10.go +++ b/venus-shared/actors/builtin/multisig/message.v10.go @@ -10,7 +10,7 @@ import ( actorstypes "github.com/filecoin-project/go-state-types/actors" multisig10 "github.com/filecoin-project/go-state-types/builtin/v10/multisig" - init15 "github.com/filecoin-project/go-state-types/builtin/v15/init" + init16 "github.com/filecoin-project/go-state-types/builtin/v16/init" "github.com/filecoin-project/go-state-types/manifest" builtintypes "github.com/filecoin-project/go-state-types/builtin" @@ -60,7 +60,7 @@ func (m message10) Create( } // new actors are created by invoking 'exec' on the init actor with the constructor params - execParams := &init15.ExecParams{ + execParams := &init16.ExecParams{ CodeCID: code, ConstructorParams: enc, } diff --git a/venus-shared/actors/builtin/multisig/message.v11.go b/venus-shared/actors/builtin/multisig/message.v11.go index e3387c0168..4302ddd2ba 100644 --- a/venus-shared/actors/builtin/multisig/message.v11.go +++ b/venus-shared/actors/builtin/multisig/message.v11.go @@ -10,7 +10,7 @@ import ( actorstypes "github.com/filecoin-project/go-state-types/actors" multisig11 "github.com/filecoin-project/go-state-types/builtin/v11/multisig" - init15 "github.com/filecoin-project/go-state-types/builtin/v15/init" + init16 "github.com/filecoin-project/go-state-types/builtin/v16/init" "github.com/filecoin-project/go-state-types/manifest" builtintypes "github.com/filecoin-project/go-state-types/builtin" @@ -60,7 +60,7 @@ func (m message11) Create( } // new actors are created by invoking 'exec' on the init actor with the constructor params - execParams := &init15.ExecParams{ + execParams := &init16.ExecParams{ CodeCID: code, ConstructorParams: enc, } diff --git a/venus-shared/actors/builtin/multisig/message.v12.go b/venus-shared/actors/builtin/multisig/message.v12.go index b4779a7279..919b1ff4b3 100644 --- a/venus-shared/actors/builtin/multisig/message.v12.go +++ b/venus-shared/actors/builtin/multisig/message.v12.go @@ -10,7 +10,7 @@ import ( actorstypes "github.com/filecoin-project/go-state-types/actors" multisig12 "github.com/filecoin-project/go-state-types/builtin/v12/multisig" - init15 "github.com/filecoin-project/go-state-types/builtin/v15/init" + init16 "github.com/filecoin-project/go-state-types/builtin/v16/init" "github.com/filecoin-project/go-state-types/manifest" builtintypes "github.com/filecoin-project/go-state-types/builtin" @@ -60,7 +60,7 @@ func (m message12) Create( } // new actors are created by invoking 'exec' on the init actor with the constructor params - execParams := &init15.ExecParams{ + execParams := &init16.ExecParams{ CodeCID: code, ConstructorParams: enc, } diff --git a/venus-shared/actors/builtin/multisig/message.v13.go b/venus-shared/actors/builtin/multisig/message.v13.go index 136ff056e4..15dfd3ee16 100644 --- a/venus-shared/actors/builtin/multisig/message.v13.go +++ b/venus-shared/actors/builtin/multisig/message.v13.go @@ -10,7 +10,7 @@ import ( actorstypes "github.com/filecoin-project/go-state-types/actors" multisig13 "github.com/filecoin-project/go-state-types/builtin/v13/multisig" - init15 "github.com/filecoin-project/go-state-types/builtin/v15/init" + init16 "github.com/filecoin-project/go-state-types/builtin/v16/init" "github.com/filecoin-project/go-state-types/manifest" builtintypes "github.com/filecoin-project/go-state-types/builtin" @@ -60,7 +60,7 @@ func (m message13) Create( } // new actors are created by invoking 'exec' on the init actor with the constructor params - execParams := &init15.ExecParams{ + execParams := &init16.ExecParams{ CodeCID: code, ConstructorParams: enc, } diff --git a/venus-shared/actors/builtin/multisig/message.v14.go b/venus-shared/actors/builtin/multisig/message.v14.go index 0ea9c8f61b..d44991cf6c 100644 --- a/venus-shared/actors/builtin/multisig/message.v14.go +++ b/venus-shared/actors/builtin/multisig/message.v14.go @@ -10,7 +10,7 @@ import ( actorstypes "github.com/filecoin-project/go-state-types/actors" multisig14 "github.com/filecoin-project/go-state-types/builtin/v14/multisig" - init15 "github.com/filecoin-project/go-state-types/builtin/v15/init" + init16 "github.com/filecoin-project/go-state-types/builtin/v16/init" "github.com/filecoin-project/go-state-types/manifest" builtintypes "github.com/filecoin-project/go-state-types/builtin" @@ -60,7 +60,7 @@ func (m message14) Create( } // new actors are created by invoking 'exec' on the init actor with the constructor params - execParams := &init15.ExecParams{ + execParams := &init16.ExecParams{ CodeCID: code, ConstructorParams: enc, } diff --git a/venus-shared/actors/builtin/multisig/message.v15.go b/venus-shared/actors/builtin/multisig/message.v15.go index 389090ab4d..f489073696 100644 --- a/venus-shared/actors/builtin/multisig/message.v15.go +++ b/venus-shared/actors/builtin/multisig/message.v15.go @@ -9,8 +9,8 @@ import ( "github.com/filecoin-project/go-state-types/abi" actorstypes "github.com/filecoin-project/go-state-types/actors" - init15 "github.com/filecoin-project/go-state-types/builtin/v15/init" multisig15 "github.com/filecoin-project/go-state-types/builtin/v15/multisig" + init16 "github.com/filecoin-project/go-state-types/builtin/v16/init" "github.com/filecoin-project/go-state-types/manifest" builtintypes "github.com/filecoin-project/go-state-types/builtin" @@ -60,7 +60,7 @@ func (m message15) Create( } // new actors are created by invoking 'exec' on the init actor with the constructor params - execParams := &init15.ExecParams{ + execParams := &init16.ExecParams{ CodeCID: code, ConstructorParams: enc, } diff --git a/venus-shared/actors/builtin/multisig/message.v16.go b/venus-shared/actors/builtin/multisig/message.v16.go new file mode 100644 index 0000000000..bcf3a2022d --- /dev/null +++ b/venus-shared/actors/builtin/multisig/message.v16.go @@ -0,0 +1,80 @@ +// FETCHED FROM LOTUS: builtin/multisig/message.go.template + +package multisig + +import ( + "fmt" + + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + + actorstypes "github.com/filecoin-project/go-state-types/actors" + init16 "github.com/filecoin-project/go-state-types/builtin/v16/init" + multisig16 "github.com/filecoin-project/go-state-types/builtin/v16/multisig" + "github.com/filecoin-project/go-state-types/manifest" + + builtintypes "github.com/filecoin-project/go-state-types/builtin" + "github.com/filecoin-project/venus/venus-shared/actors" + init_ "github.com/filecoin-project/venus/venus-shared/actors/builtin/init" + "github.com/filecoin-project/venus/venus-shared/actors/types" +) + +type message16 struct{ message0 } + +func (m message16) 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, fmt.Errorf("cannot require signing of more addresses than provided for multisig") + } + + if threshold == 0 { + threshold = lenAddrs + } + + if m.from == address.Undef { + return nil, fmt.Errorf("must provide source address") + } + + // Set up constructor parameters for multisig + msigParams := &multisig16.ConstructorParams{ + Signers: signers, + NumApprovalsThreshold: threshold, + UnlockDuration: unlockDuration, + StartEpoch: unlockStart, + } + + enc, actErr := actors.SerializeParams(msigParams) + if actErr != nil { + return nil, actErr + } + + code, ok := actors.GetActorCodeID(actorstypes.Version16, manifest.MultisigKey) + if !ok { + return nil, fmt.Errorf("failed to get multisig code ID") + } + + // new actors are created by invoking 'exec' on the init actor with the constructor params + execParams := &init16.ExecParams{ + CodeCID: code, + ConstructorParams: enc, + } + + enc, actErr = actors.SerializeParams(execParams) + if actErr != nil { + return nil, actErr + } + + return &types.Message{ + To: init_.Address, + From: m.from, + Method: builtintypes.MethodsInit.Exec, + Params: enc, + Value: initialAmount, + }, nil +} diff --git a/venus-shared/actors/builtin/multisig/message.v8.go b/venus-shared/actors/builtin/multisig/message.v8.go index 66458aca50..f4f5e0637b 100644 --- a/venus-shared/actors/builtin/multisig/message.v8.go +++ b/venus-shared/actors/builtin/multisig/message.v8.go @@ -9,7 +9,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" actorstypes "github.com/filecoin-project/go-state-types/actors" - init15 "github.com/filecoin-project/go-state-types/builtin/v15/init" + init16 "github.com/filecoin-project/go-state-types/builtin/v16/init" multisig8 "github.com/filecoin-project/go-state-types/builtin/v8/multisig" "github.com/filecoin-project/go-state-types/manifest" @@ -60,7 +60,7 @@ func (m message8) Create( } // new actors are created by invoking 'exec' on the init actor with the constructor params - execParams := &init15.ExecParams{ + execParams := &init16.ExecParams{ CodeCID: code, ConstructorParams: enc, } diff --git a/venus-shared/actors/builtin/multisig/message.v9.go b/venus-shared/actors/builtin/multisig/message.v9.go index 9985ebc159..dcb6a11227 100644 --- a/venus-shared/actors/builtin/multisig/message.v9.go +++ b/venus-shared/actors/builtin/multisig/message.v9.go @@ -9,7 +9,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" actorstypes "github.com/filecoin-project/go-state-types/actors" - init15 "github.com/filecoin-project/go-state-types/builtin/v15/init" + init16 "github.com/filecoin-project/go-state-types/builtin/v16/init" multisig9 "github.com/filecoin-project/go-state-types/builtin/v9/multisig" "github.com/filecoin-project/go-state-types/manifest" @@ -60,7 +60,7 @@ func (m message9) Create( } // new actors are created by invoking 'exec' on the init actor with the constructor params - execParams := &init15.ExecParams{ + execParams := &init16.ExecParams{ CodeCID: code, ConstructorParams: enc, } diff --git a/venus-shared/actors/builtin/multisig/state.v16.go b/venus-shared/actors/builtin/multisig/state.v16.go new file mode 100644 index 0000000000..6387686155 --- /dev/null +++ b/venus-shared/actors/builtin/multisig/state.v16.go @@ -0,0 +1,140 @@ +// FETCHED FROM LOTUS: builtin/multisig/state.go.template + +package multisig + +import ( + "bytes" + "encoding/binary" + "fmt" + + actorstypes "github.com/filecoin-project/go-state-types/actors" + + "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/go-state-types/manifest" + "github.com/filecoin-project/venus/venus-shared/actors" + "github.com/filecoin-project/venus/venus-shared/actors/adt" + + builtin16 "github.com/filecoin-project/go-state-types/builtin" + msig16 "github.com/filecoin-project/go-state-types/builtin/v16/multisig" + adt16 "github.com/filecoin-project/go-state-types/builtin/v16/util/adt" +) + +var _ State = (*state16)(nil) + +func load16(store adt.Store, root cid.Cid) (State, error) { + out := state16{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +func make16(store adt.Store, signers []address.Address, threshold uint64, startEpoch abi.ChainEpoch, unlockDuration abi.ChainEpoch, initialBalance abi.TokenAmount) (State, error) { + out := state16{store: store} + out.State = msig16.State{} + out.State.Signers = signers + out.State.NumApprovalsThreshold = threshold + out.State.StartEpoch = startEpoch + out.State.UnlockDuration = unlockDuration + out.State.InitialBalance = initialBalance + + em, err := adt16.StoreEmptyMap(store, builtin16.DefaultHamtBitwidth) + if err != nil { + return nil, err + } + + out.State.PendingTxns = em + + return &out, nil +} + +type state16 struct { + msig16.State + store adt.Store +} + +func (s *state16) LockedBalance(currEpoch abi.ChainEpoch) (abi.TokenAmount, error) { + return s.State.AmountLocked(currEpoch - s.State.StartEpoch), nil +} + +func (s *state16) StartEpoch() (abi.ChainEpoch, error) { + return s.State.StartEpoch, nil +} + +func (s *state16) UnlockDuration() (abi.ChainEpoch, error) { + return s.State.UnlockDuration, nil +} + +func (s *state16) InitialBalance() (abi.TokenAmount, error) { + return s.State.InitialBalance, nil +} + +func (s *state16) Threshold() (uint64, error) { + return s.State.NumApprovalsThreshold, nil +} + +func (s *state16) Signers() ([]address.Address, error) { + return s.State.Signers, nil +} + +func (s *state16) ForEachPendingTxn(cb func(id int64, txn Transaction) error) error { + arr, err := adt16.AsMap(s.store, s.State.PendingTxns, builtin16.DefaultHamtBitwidth) + if err != nil { + return err + } + var out msig16.Transaction + return arr.ForEach(&out, func(key string) error { + txid, n := binary.Varint([]byte(key)) + if n <= 0 { + return fmt.Errorf("invalid pending transaction key: %v", key) + } + return cb(txid, (Transaction)(out)) //nolint:unconvert + }) +} + +func (s *state16) PendingTxnChanged(other State) (bool, error) { + other16, ok := other.(*state16) + if !ok { + // treat an upgrade as a change, always + return true, nil + } + return !s.State.PendingTxns.Equals(other16.PendingTxns), nil +} + +func (s *state16) transactions() (adt.Map, error) { + return adt16.AsMap(s.store, s.PendingTxns, builtin16.DefaultHamtBitwidth) +} + +func (s *state16) decodeTransaction(val *cbg.Deferred) (Transaction, error) { + var tx msig16.Transaction + if err := tx.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { + return Transaction{}, err + } + return Transaction(tx), nil +} + +func (s *state16) GetState() interface{} { + return &s.State +} + +func (s *state16) ActorKey() string { + return manifest.MultisigKey +} + +func (s *state16) ActorVersion() actorstypes.Version { + return actorstypes.Version16 +} + +func (s *state16) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/venus-shared/actors/builtin/paych/actor.go b/venus-shared/actors/builtin/paych/actor.go index 4c4383a9f0..3cc8a47419 100644 --- a/venus-shared/actors/builtin/paych/actor.go +++ b/venus-shared/actors/builtin/paych/actor.go @@ -71,6 +71,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) { case actorstypes.Version15: return load15(store, act.Head) + case actorstypes.Version16: + return load16(store, act.Head) + } } @@ -200,6 +203,9 @@ func Message(version actorstypes.Version, from address.Address) MessageBuilder { case actorstypes.Version15: return message15{from} + case actorstypes.Version16: + return message16{from} + default: panic(fmt.Sprintf("unsupported actors version: %d", version)) } @@ -245,5 +251,6 @@ func AllCodes() []cid.Cid { (&state13{}).Code(), (&state14{}).Code(), (&state15{}).Code(), + (&state16{}).Code(), } } diff --git a/venus-shared/actors/builtin/paych/message.v16.go b/venus-shared/actors/builtin/paych/message.v16.go new file mode 100644 index 0000000000..390c862135 --- /dev/null +++ b/venus-shared/actors/builtin/paych/message.v16.go @@ -0,0 +1,113 @@ +// FETCHED FROM LOTUS: builtin/paych/message.go.template + +package paych + +import ( + "fmt" + + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + + paychtypes "github.com/filecoin-project/go-state-types/builtin/v8/paych" + + actorstypes "github.com/filecoin-project/go-state-types/actors" + builtin16 "github.com/filecoin-project/go-state-types/builtin" + init16 "github.com/filecoin-project/go-state-types/builtin/v16/init" + paych16 "github.com/filecoin-project/go-state-types/builtin/v16/paych" + + "github.com/filecoin-project/venus/venus-shared/actors" + init_ "github.com/filecoin-project/venus/venus-shared/actors/builtin/init" + "github.com/filecoin-project/venus/venus-shared/actors/types" +) + +type message16 struct{ from address.Address } + +func (m message16) Create(to address.Address, initialAmount abi.TokenAmount) (*types.Message, error) { + + actorCodeID, ok := actors.GetActorCodeID(actorstypes.Version16, "paymentchannel") + if !ok { + return nil, fmt.Errorf("error getting actor paymentchannel code id for actor version %d", 16) + } + + params, aerr := actors.SerializeParams(&paych16.ConstructorParams{From: m.from, To: to}) + if aerr != nil { + return nil, aerr + } + enc, aerr := actors.SerializeParams(&init16.ExecParams{ + CodeCID: actorCodeID, + ConstructorParams: params, + }) + if aerr != nil { + return nil, aerr + } + + return &types.Message{ + To: init_.Address, + From: m.from, + Value: initialAmount, + Method: builtin16.MethodsInit.Exec, + Params: enc, + }, nil +} + +func (m message16) Update(paych address.Address, sv *paychtypes.SignedVoucher, secret []byte) (*types.Message, error) { + params, aerr := actors.SerializeParams(&paych16.UpdateChannelStateParams{ + + Sv: toV16SignedVoucher(*sv), + + Secret: secret, + }) + if aerr != nil { + return nil, aerr + } + + return &types.Message{ + To: paych, + From: m.from, + Value: abi.NewTokenAmount(0), + Method: builtin16.MethodsPaych.UpdateChannelState, + Params: params, + }, nil +} + +func toV16SignedVoucher(sv paychtypes.SignedVoucher) paych16.SignedVoucher { + merges := make([]paych16.Merge, len(sv.Merges)) + for i := range sv.Merges { + merges[i] = paych16.Merge{ + Lane: sv.Merges[i].Lane, + Nonce: sv.Merges[i].Nonce, + } + } + + return paych16.SignedVoucher{ + ChannelAddr: sv.ChannelAddr, + TimeLockMin: sv.TimeLockMin, + TimeLockMax: sv.TimeLockMax, + SecretHash: sv.SecretHash, + Extra: (*paych16.ModVerifyParams)(sv.Extra), + Lane: sv.Lane, + Nonce: sv.Nonce, + Amount: sv.Amount, + MinSettleHeight: sv.MinSettleHeight, + Merges: merges, + Signature: sv.Signature, + } +} + +func (m message16) Settle(paych address.Address) (*types.Message, error) { + return &types.Message{ + To: paych, + From: m.from, + Value: abi.NewTokenAmount(0), + Method: builtin16.MethodsPaych.Settle, + }, nil +} + +func (m message16) Collect(paych address.Address) (*types.Message, error) { + return &types.Message{ + To: paych, + From: m.from, + Value: abi.NewTokenAmount(0), + Method: builtin16.MethodsPaych.Collect, + }, nil +} diff --git a/venus-shared/actors/builtin/paych/state.v16.go b/venus-shared/actors/builtin/paych/state.v16.go new file mode 100644 index 0000000000..3f78fb2e91 --- /dev/null +++ b/venus-shared/actors/builtin/paych/state.v16.go @@ -0,0 +1,138 @@ +// FETCHED FROM LOTUS: builtin/paych/state.go.template + +package paych + +import ( + "fmt" + + actorstypes "github.com/filecoin-project/go-state-types/actors" + "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/go-state-types/manifest" + "github.com/filecoin-project/venus/venus-shared/actors" + "github.com/filecoin-project/venus/venus-shared/actors/adt" + + paych16 "github.com/filecoin-project/go-state-types/builtin/v16/paych" + adt16 "github.com/filecoin-project/go-state-types/builtin/v16/util/adt" +) + +var _ State = (*state16)(nil) + +func load16(store adt.Store, root cid.Cid) (State, error) { + out := state16{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +func make16(store adt.Store) (State, error) { + out := state16{store: store} + out.State = paych16.State{} + return &out, nil +} + +type state16 struct { + paych16.State + store adt.Store + lsAmt *adt16.Array +} + +// Channel owner, who has funded the actor +func (s *state16) From() (address.Address, error) { + return s.State.From, nil +} + +// Recipient of payouts from channel +func (s *state16) To() (address.Address, error) { + return s.State.To, nil +} + +// Height at which the channel can be `Collected` +func (s *state16) SettlingAt() (abi.ChainEpoch, error) { + return s.State.SettlingAt, nil +} + +// Amount successfully redeemed through the payment channel, paid out on `Collect()` +func (s *state16) ToSend() (abi.TokenAmount, error) { + return s.State.ToSend, nil +} + +func (s *state16) getOrLoadLsAmt() (*adt16.Array, error) { + if s.lsAmt != nil { + return s.lsAmt, nil + } + + // Get the lane state from the chain + lsamt, err := adt16.AsArray(s.store, s.State.LaneStates, paych16.LaneStatesAmtBitwidth) + if err != nil { + return nil, err + } + + s.lsAmt = lsamt + return lsamt, nil +} + +// Get total number of lanes +func (s *state16) LaneCount() (uint64, error) { + lsamt, err := s.getOrLoadLsAmt() + if err != nil { + return 0, err + } + return lsamt.Length(), nil +} + +func (s *state16) GetState() interface{} { + return &s.State +} + +// Iterate lane states +func (s *state16) 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 paych16.LaneState + return lsamt.ForEach(&ls, func(i int64) error { + return cb(uint64(i), &laneState16{ls}) + }) +} + +type laneState16 struct { + paych16.LaneState +} + +func (ls *laneState16) Redeemed() (big.Int, error) { + return ls.LaneState.Redeemed, nil +} + +func (ls *laneState16) Nonce() (uint64, error) { + return ls.LaneState.Nonce, nil +} + +func (s *state16) ActorKey() string { + return manifest.PaychKey +} + +func (s *state16) ActorVersion() actorstypes.Version { + return actorstypes.Version16 +} + +func (s *state16) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/venus-shared/actors/builtin/power/actor.go b/venus-shared/actors/builtin/power/actor.go index e4a2a25f86..03eea2cfc5 100644 --- a/venus-shared/actors/builtin/power/actor.go +++ b/venus-shared/actors/builtin/power/actor.go @@ -34,12 +34,12 @@ import ( builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin" - builtin15 "github.com/filecoin-project/go-state-types/builtin" + builtin16 "github.com/filecoin-project/go-state-types/builtin" ) var ( - Address = builtin15.StoragePowerActorAddr - Methods = builtin15.MethodsPower + Address = builtin16.StoragePowerActorAddr + Methods = builtin16.MethodsPower ) func Load(store adt.Store, act *types.Actor) (State, error) { @@ -74,6 +74,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) { case actorstypes.Version15: return load15(store, act.Head) + case actorstypes.Version16: + return load16(store, act.Head) + } } @@ -153,6 +156,9 @@ func MakeState(store adt.Store, av actorstypes.Version) (State, error) { case actorstypes.Version15: return make15(store) + case actorstypes.Version16: + return make16(store) + } return nil, fmt.Errorf("unknown actor version %d", av) } @@ -234,5 +240,6 @@ func AllCodes() []cid.Cid { (&state13{}).Code(), (&state14{}).Code(), (&state15{}).Code(), + (&state16{}).Code(), } } diff --git a/venus-shared/actors/builtin/power/state.v16.go b/venus-shared/actors/builtin/power/state.v16.go new file mode 100644 index 0000000000..1a411eecab --- /dev/null +++ b/venus-shared/actors/builtin/power/state.v16.go @@ -0,0 +1,218 @@ +// FETCHED FROM LOTUS: builtin/power/state.go.template + +package power + +import ( + "bytes" + "fmt" + + actorstypes "github.com/filecoin-project/go-state-types/actors" + + "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/go-state-types/manifest" + "github.com/filecoin-project/venus/venus-shared/actors" + "github.com/filecoin-project/venus/venus-shared/actors/adt" + "github.com/filecoin-project/venus/venus-shared/actors/builtin" + + builtin16 "github.com/filecoin-project/go-state-types/builtin" + power16 "github.com/filecoin-project/go-state-types/builtin/v16/power" + adt16 "github.com/filecoin-project/go-state-types/builtin/v16/util/adt" +) + +var _ State = (*state16)(nil) + +func load16(store adt.Store, root cid.Cid) (State, error) { + out := state16{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +func make16(store adt.Store) (State, error) { + out := state16{store: store} + + s, err := power16.ConstructState(store) + if err != nil { + return nil, err + } + + out.State = *s + + return &out, nil +} + +type state16 struct { + power16.State + store adt.Store +} + +func (s *state16) TotalLocked() (abi.TokenAmount, error) { + return s.TotalPledgeCollateral, nil +} + +func (s *state16) 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 *state16) TotalCommitted() (Claim, error) { + return Claim{ + RawBytePower: s.TotalBytesCommitted, + QualityAdjPower: s.TotalQABytesCommitted, + }, nil +} + +func (s *state16) MinerPower(addr address.Address) (Claim, bool, error) { + claims, err := s.claims() + if err != nil { + return Claim{}, false, err + } + var claim power16.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 *state16) MinerNominalPowerMeetsConsensusMinimum(a address.Address) (bool, error) { + return s.State.MinerNominalPowerMeetsConsensusMinimum(s.store, a) +} + +func (s *state16) TotalPowerSmoothed() (builtin.FilterEstimate, error) { + return builtin.FilterEstimate(s.State.ThisEpochQAPowerSmoothed), nil +} + +func (s *state16) MinerCounts() (uint64, uint64, error) { + return uint64(s.State.MinerAboveMinPowerCount), uint64(s.State.MinerCount), nil +} + +func (s *state16) RampStartEpoch() int64 { + return s.State.RampStartEpoch +} + +func (s *state16) RampDurationEpochs() uint64 { + return s.State.RampDurationEpochs +} + +func (s *state16) 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 *state16) ForEachClaim(cb func(miner address.Address, claim Claim) error) error { + claims, err := s.claims() + if err != nil { + return err + } + + var claim power16.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 *state16) ClaimsChanged(other State) (bool, error) { + other16, ok := other.(*state16) + if !ok { + // treat an upgrade as a change, always + return true, nil + } + return !s.State.Claims.Equals(other16.State.Claims), nil +} + +func (s *state16) SetTotalQualityAdjPower(p abi.StoragePower) error { + s.State.TotalQualityAdjPower = p + return nil +} + +func (s *state16) SetTotalRawBytePower(p abi.StoragePower) error { + s.State.TotalRawBytePower = p + return nil +} + +func (s *state16) SetThisEpochQualityAdjPower(p abi.StoragePower) error { + s.State.ThisEpochQualityAdjPower = p + return nil +} + +func (s *state16) SetThisEpochRawBytePower(p abi.StoragePower) error { + s.State.ThisEpochRawBytePower = p + return nil +} + +func (s *state16) GetState() interface{} { + return &s.State +} + +func (s *state16) claims() (adt.Map, error) { + return adt16.AsMap(s.store, s.Claims, builtin16.DefaultHamtBitwidth) +} + +func (s *state16) decodeClaim(val *cbg.Deferred) (Claim, error) { + var ci power16.Claim + if err := ci.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { + return Claim{}, err + } + return fromV16Claim(ci), nil +} + +func fromV16Claim(v16 power16.Claim) Claim { + return Claim{ + RawBytePower: v16.RawBytePower, + QualityAdjPower: v16.QualityAdjPower, + } +} + +func (s *state16) ActorKey() string { + return manifest.PowerKey +} + +func (s *state16) ActorVersion() actorstypes.Version { + return actorstypes.Version16 +} + +func (s *state16) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/venus-shared/actors/builtin/registry.go b/venus-shared/actors/builtin/registry.go index 03fc8b6b51..949d743e87 100644 --- a/venus-shared/actors/builtin/registry.go +++ b/venus-shared/actors/builtin/registry.go @@ -152,6 +152,25 @@ import ( evm15 "github.com/filecoin-project/go-state-types/builtin/v15/evm" placeholder15 "github.com/filecoin-project/go-state-types/builtin/v15/placeholder" + account16 "github.com/filecoin-project/go-state-types/builtin/v16/account" + cron16 "github.com/filecoin-project/go-state-types/builtin/v16/cron" + _init16 "github.com/filecoin-project/go-state-types/builtin/v16/init" + market16 "github.com/filecoin-project/go-state-types/builtin/v16/market" + miner16 "github.com/filecoin-project/go-state-types/builtin/v16/miner" + multisig16 "github.com/filecoin-project/go-state-types/builtin/v16/multisig" + paych16 "github.com/filecoin-project/go-state-types/builtin/v16/paych" + power16 "github.com/filecoin-project/go-state-types/builtin/v16/power" + reward16 "github.com/filecoin-project/go-state-types/builtin/v16/reward" + system16 "github.com/filecoin-project/go-state-types/builtin/v16/system" + verifreg16 "github.com/filecoin-project/go-state-types/builtin/v16/verifreg" + + datacap16 "github.com/filecoin-project/go-state-types/builtin/v16/datacap" + + eam16 "github.com/filecoin-project/go-state-types/builtin/v16/eam" + ethaccount16 "github.com/filecoin-project/go-state-types/builtin/v16/ethaccount" + evm16 "github.com/filecoin-project/go-state-types/builtin/v16/evm" + placeholder16 "github.com/filecoin-project/go-state-types/builtin/v16/placeholder" + "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/cbor" "github.com/filecoin-project/go-state-types/manifest" @@ -1000,6 +1019,110 @@ func MakeRegistry(av actorstypes.Version) []RegistryEntry { } } + case actorstypes.Version16: + for key, codeID := range codeIDs { + switch key { + case manifest.AccountKey: + registry = append(registry, RegistryEntry{ + code: codeID, + methods: account16.Methods, + state: new(account16.State), + }) + case manifest.CronKey: + registry = append(registry, RegistryEntry{ + code: codeID, + methods: cron16.Methods, + state: new(cron16.State), + }) + case manifest.InitKey: + registry = append(registry, RegistryEntry{ + code: codeID, + methods: _init16.Methods, + state: new(_init16.State), + }) + case manifest.MarketKey: + registry = append(registry, RegistryEntry{ + code: codeID, + methods: market16.Methods, + state: new(market16.State), + }) + case manifest.MinerKey: + registry = append(registry, RegistryEntry{ + code: codeID, + methods: miner16.Methods, + state: new(miner16.State), + }) + case manifest.MultisigKey: + registry = append(registry, RegistryEntry{ + code: codeID, + methods: multisig16.Methods, + state: new(multisig16.State), + }) + case manifest.PaychKey: + registry = append(registry, RegistryEntry{ + code: codeID, + methods: paych16.Methods, + state: new(paych16.State), + }) + case manifest.PowerKey: + registry = append(registry, RegistryEntry{ + code: codeID, + methods: power16.Methods, + state: new(power16.State), + }) + case manifest.RewardKey: + registry = append(registry, RegistryEntry{ + code: codeID, + methods: reward16.Methods, + state: new(reward16.State), + }) + case manifest.SystemKey: + registry = append(registry, RegistryEntry{ + code: codeID, + methods: system16.Methods, + state: new(system16.State), + }) + case manifest.VerifregKey: + registry = append(registry, RegistryEntry{ + code: codeID, + methods: verifreg16.Methods, + state: new(verifreg16.State), + }) + case manifest.DatacapKey: + registry = append(registry, RegistryEntry{ + code: codeID, + methods: datacap16.Methods, + state: new(datacap16.State), + }) + + case manifest.EvmKey: + registry = append(registry, RegistryEntry{ + code: codeID, + methods: evm16.Methods, + state: new(evm16.State), + }) + case manifest.EamKey: + registry = append(registry, RegistryEntry{ + code: codeID, + methods: eam16.Methods, + state: nil, + }) + case manifest.PlaceholderKey: + registry = append(registry, RegistryEntry{ + code: codeID, + methods: placeholder16.Methods, + state: nil, + }) + case manifest.EthAccountKey: + registry = append(registry, RegistryEntry{ + code: codeID, + methods: ethaccount16.Methods, + state: nil, + }) + + } + } + default: panic("expected version v8 and up only, use specs-actors for v0-7") } diff --git a/venus-shared/actors/builtin/reward/actor.go b/venus-shared/actors/builtin/reward/actor.go index ffcd3038e7..904d2787bb 100644 --- a/venus-shared/actors/builtin/reward/actor.go +++ b/venus-shared/actors/builtin/reward/actor.go @@ -27,7 +27,7 @@ import ( builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin" - builtin15 "github.com/filecoin-project/go-state-types/builtin" + builtin16 "github.com/filecoin-project/go-state-types/builtin" "github.com/filecoin-project/go-state-types/manifest" "github.com/filecoin-project/venus/venus-shared/actors/adt" @@ -36,8 +36,8 @@ import ( ) var ( - Address = builtin15.RewardActorAddr - Methods = builtin15.MethodsReward + Address = builtin16.RewardActorAddr + Methods = builtin16.MethodsReward ) func Load(store adt.Store, act *types.Actor) (State, error) { @@ -72,6 +72,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) { case actorstypes.Version15: return load15(store, act.Head) + case actorstypes.Version16: + return load16(store, act.Head) + } } @@ -151,6 +154,9 @@ func MakeState(store adt.Store, av actorstypes.Version, currRealizedPower abi.St case actorstypes.Version15: return make15(store, currRealizedPower) + case actorstypes.Version16: + return make16(store, currRealizedPower) + } return nil, fmt.Errorf("unknown actor version %d", av) } @@ -205,5 +211,6 @@ func AllCodes() []cid.Cid { (&state13{}).Code(), (&state14{}).Code(), (&state15{}).Code(), + (&state16{}).Code(), } } diff --git a/venus-shared/actors/builtin/reward/state.v16.go b/venus-shared/actors/builtin/reward/state.v16.go new file mode 100644 index 0000000000..b768027aba --- /dev/null +++ b/venus-shared/actors/builtin/reward/state.v16.go @@ -0,0 +1,124 @@ +// FETCHED FROM LOTUS: builtin/reward/state.go.template + +package reward + +import ( + "fmt" + + "github.com/filecoin-project/go-state-types/abi" + actorstypes "github.com/filecoin-project/go-state-types/actors" + "github.com/ipfs/go-cid" + + "github.com/filecoin-project/go-state-types/manifest" + "github.com/filecoin-project/venus/venus-shared/actors" + "github.com/filecoin-project/venus/venus-shared/actors/adt" + "github.com/filecoin-project/venus/venus-shared/actors/builtin" + + miner16 "github.com/filecoin-project/go-state-types/builtin/v16/miner" + reward16 "github.com/filecoin-project/go-state-types/builtin/v16/reward" + smoothing16 "github.com/filecoin-project/go-state-types/builtin/v16/util/smoothing" +) + +var _ State = (*state16)(nil) + +func load16(store adt.Store, root cid.Cid) (State, error) { + out := state16{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +func make16(store adt.Store, currRealizedPower abi.StoragePower) (State, error) { + out := state16{store: store} + out.State = *reward16.ConstructState(currRealizedPower) + return &out, nil +} + +type state16 struct { + reward16.State + store adt.Store +} + +func (s *state16) ThisEpochReward() (abi.TokenAmount, error) { + return s.State.ThisEpochReward, nil +} + +func (s *state16) ThisEpochRewardSmoothed() (builtin.FilterEstimate, error) { + + return builtin.FilterEstimate{ + PositionEstimate: s.State.ThisEpochRewardSmoothed.PositionEstimate, + VelocityEstimate: s.State.ThisEpochRewardSmoothed.VelocityEstimate, + }, nil + +} + +func (s *state16) ThisEpochBaselinePower() (abi.StoragePower, error) { + return s.State.ThisEpochBaselinePower, nil +} + +func (s *state16) TotalStoragePowerReward() (abi.TokenAmount, error) { + return s.State.TotalStoragePowerReward, nil +} + +func (s *state16) EffectiveBaselinePower() (abi.StoragePower, error) { + return s.State.EffectiveBaselinePower, nil +} + +func (s *state16) EffectiveNetworkTime() (abi.ChainEpoch, error) { + return s.State.EffectiveNetworkTime, nil +} + +func (s *state16) CumsumBaseline() (reward16.Spacetime, error) { + return s.State.CumsumBaseline, nil +} + +func (s *state16) CumsumRealized() (reward16.Spacetime, error) { + return s.State.CumsumRealized, nil +} + +func (s *state16) InitialPledgeForPower(qaPower abi.StoragePower, _ abi.TokenAmount, networkQAPower *builtin.FilterEstimate, circSupply abi.TokenAmount, epochsSinceRampStart int64, rampDurationEpochs uint64) (abi.TokenAmount, error) { + return miner16.InitialPledgeForPower( + qaPower, + s.State.ThisEpochBaselinePower, + s.State.ThisEpochRewardSmoothed, + smoothing16.FilterEstimate{ + PositionEstimate: networkQAPower.PositionEstimate, + VelocityEstimate: networkQAPower.VelocityEstimate, + }, + circSupply, + epochsSinceRampStart, + rampDurationEpochs, + ), nil +} + +func (s *state16) PreCommitDepositForPower(networkQAPower builtin.FilterEstimate, sectorWeight abi.StoragePower) (abi.TokenAmount, error) { + return miner16.PreCommitDepositForPower(s.State.ThisEpochRewardSmoothed, + smoothing16.FilterEstimate{ + PositionEstimate: networkQAPower.PositionEstimate, + VelocityEstimate: networkQAPower.VelocityEstimate, + }, + sectorWeight), nil +} + +func (s *state16) GetState() interface{} { + return &s.State +} + +func (s *state16) ActorKey() string { + return manifest.RewardKey +} + +func (s *state16) ActorVersion() actorstypes.Version { + return actorstypes.Version16 +} + +func (s *state16) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/venus-shared/actors/builtin/system/actor.go b/venus-shared/actors/builtin/system/actor.go index 68cc67b5e3..5c1cd4bad2 100644 --- a/venus-shared/actors/builtin/system/actor.go +++ b/venus-shared/actors/builtin/system/actor.go @@ -26,11 +26,11 @@ import ( builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin" - builtin15 "github.com/filecoin-project/go-state-types/builtin" + builtin16 "github.com/filecoin-project/go-state-types/builtin" ) var ( - Address = builtin15.SystemActorAddr + Address = builtin16.SystemActorAddr ) func Load(store adt.Store, act *types.Actor) (State, error) { @@ -65,6 +65,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) { case actorstypes.Version15: return load15(store, act.Head) + case actorstypes.Version16: + return load16(store, act.Head) + } } @@ -144,6 +147,9 @@ func MakeState(store adt.Store, av actorstypes.Version, builtinActors cid.Cid) ( case actorstypes.Version15: return make15(store, builtinActors) + case actorstypes.Version16: + return make16(store, builtinActors) + } return nil, fmt.Errorf("unknown actor version %d", av) } @@ -175,5 +181,6 @@ func AllCodes() []cid.Cid { (&state13{}).Code(), (&state14{}).Code(), (&state15{}).Code(), + (&state16{}).Code(), } } diff --git a/venus-shared/actors/builtin/system/state.v16.go b/venus-shared/actors/builtin/system/state.v16.go new file mode 100644 index 0000000000..955143090b --- /dev/null +++ b/venus-shared/actors/builtin/system/state.v16.go @@ -0,0 +1,75 @@ +// FETCHED FROM LOTUS: builtin/system/state.go.template + +package system + +import ( + "fmt" + + actorstypes "github.com/filecoin-project/go-state-types/actors" + "github.com/filecoin-project/go-state-types/manifest" + + "github.com/ipfs/go-cid" + + "github.com/filecoin-project/venus/venus-shared/actors" + "github.com/filecoin-project/venus/venus-shared/actors/adt" + + system16 "github.com/filecoin-project/go-state-types/builtin/v16/system" +) + +var _ State = (*state16)(nil) + +func load16(store adt.Store, root cid.Cid) (State, error) { + out := state16{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +func make16(store adt.Store, builtinActors cid.Cid) (State, error) { + out := state16{store: store} + out.State = system16.State{ + BuiltinActors: builtinActors, + } + return &out, nil +} + +type state16 struct { + system16.State + store adt.Store +} + +func (s *state16) GetState() interface{} { + return &s.State +} + +func (s *state16) GetBuiltinActors() cid.Cid { + + return s.State.BuiltinActors + +} + +func (s *state16) SetBuiltinActors(c cid.Cid) error { + + s.State.BuiltinActors = c + return nil + +} + +func (s *state16) ActorKey() string { + return manifest.SystemKey +} + +func (s *state16) ActorVersion() actorstypes.Version { + return actorstypes.Version16 +} + +func (s *state16) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/venus-shared/actors/builtin/verifreg/actor.go b/venus-shared/actors/builtin/verifreg/actor.go index 5184588a6a..9b66992ad5 100644 --- a/venus-shared/actors/builtin/verifreg/actor.go +++ b/venus-shared/actors/builtin/verifreg/actor.go @@ -28,7 +28,7 @@ import ( builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin" - builtin15 "github.com/filecoin-project/go-state-types/builtin" + builtin16 "github.com/filecoin-project/go-state-types/builtin" verifregtypes12 "github.com/filecoin-project/go-state-types/builtin/v12/verifreg" verifregtypes "github.com/filecoin-project/go-state-types/builtin/v9/verifreg" @@ -38,8 +38,8 @@ import ( ) var ( - Address = builtin15.VerifiedRegistryActorAddr - Methods = builtin15.MethodsVerifiedRegistry + Address = builtin16.VerifiedRegistryActorAddr + Methods = builtin16.MethodsVerifiedRegistry ) func Load(store adt.Store, act *types.Actor) (State, error) { @@ -74,6 +74,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) { case actorstypes.Version15: return load15(store, act.Head) + case actorstypes.Version16: + return load16(store, act.Head) + } } @@ -153,6 +156,9 @@ func MakeState(store adt.Store, av actorstypes.Version, rootKeyAddress address.A case actorstypes.Version15: return make15(store, rootKeyAddress) + case actorstypes.Version16: + return make16(store, rootKeyAddress) + } return nil, fmt.Errorf("unknown actor version %d", av) } @@ -197,6 +203,7 @@ func AllCodes() []cid.Cid { (&state13{}).Code(), (&state14{}).Code(), (&state15{}).Code(), + (&state16{}).Code(), } } diff --git a/venus-shared/actors/builtin/verifreg/state.v16.go b/venus-shared/actors/builtin/verifreg/state.v16.go new file mode 100644 index 0000000000..fab7f85028 --- /dev/null +++ b/venus-shared/actors/builtin/verifreg/state.v16.go @@ -0,0 +1,199 @@ +// FETCHED FROM LOTUS: builtin/verifreg/state.go.template + +package verifreg + +import ( + "fmt" + + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + actorstypes "github.com/filecoin-project/go-state-types/actors" + "github.com/filecoin-project/go-state-types/manifest" + "github.com/ipfs/go-cid" + + "github.com/filecoin-project/venus/venus-shared/actors" + "github.com/filecoin-project/venus/venus-shared/actors/adt" + + builtin16 "github.com/filecoin-project/go-state-types/builtin" + adt16 "github.com/filecoin-project/go-state-types/builtin/v16/util/adt" + verifreg16 "github.com/filecoin-project/go-state-types/builtin/v16/verifreg" + + "github.com/filecoin-project/go-state-types/big" + + verifreg9 "github.com/filecoin-project/go-state-types/builtin/v9/verifreg" +) + +var _ State = (*state16)(nil) + +func load16(store adt.Store, root cid.Cid) (State, error) { + out := state16{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +func make16(store adt.Store, rootKeyAddress address.Address) (State, error) { + out := state16{store: store} + + s, err := verifreg16.ConstructState(store, rootKeyAddress) + if err != nil { + return nil, err + } + + out.State = *s + + return &out, nil +} + +type state16 struct { + verifreg16.State + store adt.Store +} + +func (s *state16) RootKey() (address.Address, error) { + return s.State.RootKey, nil +} + +func (s *state16) VerifiedClientDataCap(addr address.Address) (bool, abi.StoragePower, error) { + + return false, big.Zero(), fmt.Errorf("unsupported in actors v16") + +} + +func (s *state16) VerifierDataCap(addr address.Address) (bool, abi.StoragePower, error) { + return getDataCap(s.store, actors.Version16, s.verifiers, addr) +} + +func (s *state16) RemoveDataCapProposalID(verifier address.Address, client address.Address) (bool, uint64, error) { + return getRemoveDataCapProposalID(s.store, actors.Version16, s.removeDataCapProposalIDs, verifier, client) +} + +func (s *state16) ForEachVerifier(cb func(addr address.Address, dcap abi.StoragePower) error) error { + return forEachCap(s.store, actors.Version16, s.verifiers, cb) +} + +func (s *state16) ForEachClient(cb func(addr address.Address, dcap abi.StoragePower) error) error { + + return fmt.Errorf("unsupported in actors v16") + +} + +func (s *state16) verifiedClients() (adt.Map, error) { + + return nil, fmt.Errorf("unsupported in actors v16") + +} + +func (s *state16) verifiers() (adt.Map, error) { + return adt16.AsMap(s.store, s.Verifiers, builtin16.DefaultHamtBitwidth) +} + +func (s *state16) removeDataCapProposalIDs() (adt.Map, error) { + return adt16.AsMap(s.store, s.RemoveDataCapProposalIDs, builtin16.DefaultHamtBitwidth) +} + +func (s *state16) GetState() interface{} { + return &s.State +} + +func (s *state16) GetAllocation(clientIdAddr address.Address, allocationId verifreg9.AllocationId) (*Allocation, bool, error) { + + alloc, ok, err := s.FindAllocation(s.store, clientIdAddr, verifreg16.AllocationId(allocationId)) + return (*Allocation)(alloc), ok, err +} + +func (s *state16) GetAllocations(clientIdAddr address.Address) (map[AllocationId]Allocation, error) { + + v16Map, err := s.LoadAllocationsToMap(s.store, clientIdAddr) + + retMap := make(map[AllocationId]Allocation, len(v16Map)) + for k, v := range v16Map { + retMap[AllocationId(k)] = Allocation(v) + } + + return retMap, err + +} + +func (s *state16) GetAllAllocations() (map[AllocationId]Allocation, error) { + + v16Map, err := s.State.GetAllAllocations(s.store) + + retMap := make(map[AllocationId]Allocation, len(v16Map)) + for k, v := range v16Map { + retMap[AllocationId(k)] = Allocation(v) + } + + return retMap, err + +} + +func (s *state16) GetClaim(providerIdAddr address.Address, claimId verifreg9.ClaimId) (*Claim, bool, error) { + + claim, ok, err := s.FindClaim(s.store, providerIdAddr, verifreg16.ClaimId(claimId)) + return (*Claim)(claim), ok, err + +} + +func (s *state16) GetClaims(providerIdAddr address.Address) (map[ClaimId]Claim, error) { + + v16Map, err := s.LoadClaimsToMap(s.store, providerIdAddr) + + retMap := make(map[ClaimId]Claim, len(v16Map)) + for k, v := range v16Map { + retMap[ClaimId(k)] = Claim(v) + } + + return retMap, err + +} + +func (s *state16) GetAllClaims() (map[ClaimId]Claim, error) { + + v16Map, err := s.State.GetAllClaims(s.store) + + retMap := make(map[ClaimId]Claim, len(v16Map)) + for k, v := range v16Map { + retMap[ClaimId(k)] = Claim(v) + } + + return retMap, err + +} + +func (s *state16) GetClaimIdsBySector(providerIdAddr address.Address) (map[abi.SectorNumber][]ClaimId, error) { + + v16Map, err := s.LoadClaimsToMap(s.store, providerIdAddr) + + retMap := make(map[abi.SectorNumber][]ClaimId) + for k, v := range v16Map { + claims, ok := retMap[v.Sector] + if !ok { + retMap[v.Sector] = []ClaimId{ClaimId(k)} + } else { + retMap[v.Sector] = append(claims, ClaimId(k)) + } + } + + return retMap, err + +} + +func (s *state16) ActorKey() string { + return manifest.VerifregKey +} + +func (s *state16) ActorVersion() actorstypes.Version { + return actorstypes.Version16 +} + +func (s *state16) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/venus-shared/actors/builtin_actors_gen.go b/venus-shared/actors/builtin_actors_gen.go index 64d7818309..e6d0c6f990 100644 --- a/venus-shared/actors/builtin_actors_gen.go +++ b/venus-shared/actors/builtin_actors_gen.go @@ -185,6 +185,29 @@ var EmbeddedBuiltinActorsMetadata []*BuiltinActorsMetadata = []*BuiltinActorsMet "system": mustParseCid("bafk2bzacebf6qpnaem4d3kku74hyizal7rfqmxvngvnerq3gxmyqvnib4ho22"), "verifiedregistry": mustParseCid("bafk2bzacebxppwtgpstn55klmiux64pwekibcapv6v26nbfrrateth5zzsdic"), }, +}, { + Network: "butterflynet", + Version: 16, + + ManifestCid: mustParseCid("bafy2bzaceb2sef5dqd24omllj7wolsoy4wruom5wgvjxho2c7wrymznwknnag"), + Actors: map[string]cid.Cid{ + "account": mustParseCid("bafk2bzaceb6r4cgqw6bshgjbvoodkylcc2qwzutr7bfz7wjcez5gftdsurcoe"), + "cron": mustParseCid("bafk2bzaceal5a73ltfegx2z7bymcmsv6cpvstmv7hhtehhwfukoq5jv4cgkra"), + "datacap": mustParseCid("bafk2bzacedrzzej65j2frhywc2pvdxffm2rjqkqz3m7ini4emwj3h5ya2w4nm"), + "eam": mustParseCid("bafk2bzacecl7lyqmifaml3k3cxrwn6zvklul44tfxshogflzpgtknmjdsx2yg"), + "ethaccount": mustParseCid("bafk2bzaced7vjluo44pvl4wkzcpwjfkx3lvphfpoydpv3vo4bujeg47apside"), + "evm": mustParseCid("bafk2bzacea4fjai6ier4rjid7hebzf5yyotpnrvibcy7c66fljskffhgmoh56"), + "init": mustParseCid("bafk2bzaceadmv6zqn2hoelmkftwyezthyhl67pmuo3rflrzdokzhevnrezjma"), + "multisig": mustParseCid("bafk2bzacedzr27rgj7lfo3z4yfjx4fqhfaotjl2v2gmnm5olxtg2gfpy7ckmg"), + "paymentchannel": mustParseCid("bafk2bzacedcfjumckwrymqy4zzxbo5us3vqq6mfyvbh2jsto7hdikkoq5qkls"), + "placeholder": mustParseCid("bafk2bzacedfvut2myeleyq67fljcrw4kkmn5pb5dpyozovj7jpoez5irnc3ro"), + "reward": mustParseCid("bafk2bzacecxspzoypnz2cxqzghiplf6aaeff4cpfyh63iysccvpf7bpjajlk6"), + "storagemarket": mustParseCid("bafk2bzacealk2e2aygrnsx7pkp7ptdhmb5uo7ynoovp5ocaewauksnd4ujjko"), + "storageminer": mustParseCid("bafk2bzacebmvsft5tujepbnf3ynabbswd6nyr3duyieywlgybpswclppusice"), + "storagepower": mustParseCid("bafk2bzaceduvn2h6ij4wiglq7alcipdnhzm2rw5ezfct3r6ysnj7dj4nfqwgs"), + "system": mustParseCid("bafk2bzaceaprc5x33s4n6pvdqpczpek3mph7ulkehqd5zp47ve4xtetr7n7ae"), + "verifiedregistry": mustParseCid("bafk2bzacecspvdjl7dkrelltmjjy244ealajchnl5uiz5vg5k4gbff5q7bzzk"), + }, }, { Network: "calibrationnet", Version: 8, @@ -360,6 +383,29 @@ var EmbeddedBuiltinActorsMetadata []*BuiltinActorsMetadata = []*BuiltinActorsMet "system": mustParseCid("bafk2bzacecybufhea4ah2vwtp4pqxotdfk2lnrgu6cw63jstysjzzcegio4ps"), "verifiedregistry": mustParseCid("bafk2bzacedbvfxhxsdktslf2rto5kyiumvppoen2avbmpgh7ijsmkxjyua3s4"), }, +}, { + Network: "calibrationnet", + Version: 16, + + ManifestCid: mustParseCid("bafy2bzacecnhy2ffkabgzkvbjh26ne7ssi6w4ze5wivs5xvblzjeoolwt7cik"), + Actors: map[string]cid.Cid{ + "account": mustParseCid("bafk2bzacebhtin3dmygqrknd4lklq54acuty6xzkmk6ns3xbu64bgbudhjg7q"), + "cron": mustParseCid("bafk2bzacebyatbqsjismirnvq3xrnukkt6nxbrvpbn6nqlcjjrqvoi5kta4po"), + "datacap": mustParseCid("bafk2bzacecrkvyfc7u4ugyduc452jym5jh3tsdouyni4lrk7hjbo27fbdwuuc"), + "eam": mustParseCid("bafk2bzacecqrk6orfccd6aqcm3y5edtffy6psrb7pfz55bhf767bicokmogz2"), + "ethaccount": mustParseCid("bafk2bzaceauk66kcd33z3fxg5od2mcugtfimpfkzbcl5yuypboapcbclzqodu"), + "evm": mustParseCid("bafk2bzacedznjpmamqff5h3soivlqtcsjftgpuek3sbkhnxma2fkkvvsm2onw"), + "init": mustParseCid("bafk2bzaceapbix6qtxgy7uqeufs2sgpkbrvh24f2d25k35ijaibte5vv7v22w"), + "multisig": mustParseCid("bafk2bzacebt4uhg46auji5hqtabmtcxb2pryex4dgcf66w7asdnzm24kc3xak"), + "paymentchannel": mustParseCid("bafk2bzacecofzu4t4jgda6uzg4hnla432egslx4o5lw6deytee66ddpkyh3w2"), + "placeholder": mustParseCid("bafk2bzacedfvut2myeleyq67fljcrw4kkmn5pb5dpyozovj7jpoez5irnc3ro"), + "reward": mustParseCid("bafk2bzacebvl5mzxtqrzavh7nigwiuuarsrht5c6q566ilw4azzbl7sthqj7o"), + "storagemarket": mustParseCid("bafk2bzaceclswjt5oxdwtrchrmlz3p4jo5i7wpv3j5rmosdvizafdwctuvox2"), + "storageminer": mustParseCid("bafk2bzacec52wt3anzm2rzfk6kzgdxgaooa2p26fbslgmexxmgnyefiou774g"), + "storagepower": mustParseCid("bafk2bzaceakvmhul2njhpbqlegop4nid64h37opx47jjxqwdoqsxo7zbo4qjs"), + "system": mustParseCid("bafk2bzacebzreyva3m7svmdk7rvrg2e2kgomhhjhlgohdqhghyefanst4q2xi"), + "verifiedregistry": mustParseCid("bafk2bzaceavjhcx4kn7h4pjkydih7al2rrzpw3vatp4qnrmydmp56epsem76i"), + }, }, { Network: "caterpillarnet", Version: 8, @@ -544,6 +590,29 @@ var EmbeddedBuiltinActorsMetadata []*BuiltinActorsMetadata = []*BuiltinActorsMet "system": mustParseCid("bafk2bzacecwyleco2r5bjjxdj3dp26bluua3f3u4mta4wmrrslfxscb2kz37o"), "verifiedregistry": mustParseCid("bafk2bzacec4i7zpu6ca5zqcxsowiqqofqix7z5gh3k27mndpnm3wujbzuf2bk"), }, +}, { + Network: "caterpillarnet", + Version: 16, + + ManifestCid: mustParseCid("bafy2bzaced4e64mrxqrkp3xnxd3ckpxcbzsneylvrtghyw7ewsc4r43sukvbi"), + Actors: map[string]cid.Cid{ + "account": mustParseCid("bafk2bzacecnox6g2u4zsd7e3jvfjvkixzhkdkeigplsy5rhvunxqsiifzhhba"), + "cron": mustParseCid("bafk2bzacebp22of6erhezlfw65kcqrarfjqm33m2qg2uvkmkoxbmeffols5li"), + "datacap": mustParseCid("bafk2bzaced4sds53wixkyqqgg7zqzgksbfy35gyawnsxqhkmtvvmesaeurekq"), + "eam": mustParseCid("bafk2bzacecayln3yll7gyfdj3gwxsogyvbweaax7qjgktvcskvy7jhbm3x4jk"), + "ethaccount": mustParseCid("bafk2bzacebrf53cpa3jwuql6ihugkttmn3wmijmyoi3v2hcq3l5ew5ufsgxtq"), + "evm": mustParseCid("bafk2bzaceada4qpywxzfn6vnh6klrtvsqnxjxffecnxflloanekxb7smestha"), + "init": mustParseCid("bafk2bzaceamqrupb2jmi37tbkwj63xxjhqpuas5vqi7o3aco6pw2pu3jyid4i"), + "multisig": mustParseCid("bafk2bzacebkedbffj6nt544xyq6d6ikmgk7evm7otngg3ut5zqc3uunatjhd6"), + "paymentchannel": mustParseCid("bafk2bzaceb4tkjn3jokovcjumwqdihk6t76hnmkjbkyv7zrlqboudgbyonjgs"), + "placeholder": mustParseCid("bafk2bzacedfvut2myeleyq67fljcrw4kkmn5pb5dpyozovj7jpoez5irnc3ro"), + "reward": mustParseCid("bafk2bzacea4funi4emb6bmtknfzcfeezyozcyftus54wmxsyptxx2e6cttk44"), + "storagemarket": mustParseCid("bafk2bzaceb5ffkgskw6pyy6h6trpdmu3tlbxlmtozksbt5hca462qrpoyxf2s"), + "storageminer": mustParseCid("bafk2bzacecsskrrpzzgimek2qoup3is6yu4rsgrlkecgrcqtrorytrvfdoptg"), + "storagepower": mustParseCid("bafk2bzaceddx3mc3iy4snyimyy6f5vt3vhn6s2ycu3qemhzby2xc6okkniofe"), + "system": mustParseCid("bafk2bzacecm5kggtlgmqaftx5lkzbfigshza5p3dthqhsrvwmxhdp5hxiikgw"), + "verifiedregistry": mustParseCid("bafk2bzaceckvlmmqmwz7cgv2fdsmkpi3ycpdxmz6aqwthpbdtt2dq5mllnoog"), + }, }, { Network: "devnet", Version: 8, @@ -719,6 +788,29 @@ var EmbeddedBuiltinActorsMetadata []*BuiltinActorsMetadata = []*BuiltinActorsMet "system": mustParseCid("bafk2bzacebkim7xhbjjuwyqmegclkftnfoz74735yreqdcwr2i6z2kbv767ae"), "verifiedregistry": mustParseCid("bafk2bzacedd6hquizdv65nai6h5f2lfhkxgkrofn2zcrrwqi5cmbo2wotx6vm"), }, +}, { + Network: "devnet", + Version: 16, + + ManifestCid: mustParseCid("bafy2bzacec6sjrvu2umrtdt7zcmdg3s4asxdwe5lssbty73qda2qas5aeoit2"), + Actors: map[string]cid.Cid{ + "account": mustParseCid("bafk2bzaced2rd2qlkhm53dhkzrrfnn3noojni5u5i65gtnzthab63rvwojfvi"), + "cron": mustParseCid("bafk2bzaceccvueu6agbrm2p7jhv2yrx53kk6pgxbb4d5pryjl37gjc6vavo52"), + "datacap": mustParseCid("bafk2bzacebbyirtv473zmsrdaindtjtkztfyij573ok4tq77iu3sqqmwptib2"), + "eam": mustParseCid("bafk2bzaceawnymnqomdey5jhulqwbarfm75pq7sdx7pth2bdef362n4zwp3la"), + "ethaccount": mustParseCid("bafk2bzaceaghwzlxj6u6n5iz7ms5tqa7yfnvkdpaqvoz3aolqsmlaf3ehoo3u"), + "evm": mustParseCid("bafk2bzacebbujuvpj2hg4qihi5z2zx3625gnfay5ilbwjflrrw66uya7bpm34"), + "init": mustParseCid("bafk2bzaceaai3wofftjuomfj2bjdeyjr2bnb44kuad374oxdsqa6xlxjndycg"), + "multisig": mustParseCid("bafk2bzacecxfxse6sdbinuzktgdi2yf7kbqnfymq3ud7uhbpf6hz34boimaky"), + "paymentchannel": mustParseCid("bafk2bzacebbc35dhiy4o6q7o475qtdavvcy22x2okc7tzdi63d2zdxqqfxpoi"), + "placeholder": mustParseCid("bafk2bzacedfvut2myeleyq67fljcrw4kkmn5pb5dpyozovj7jpoez5irnc3ro"), + "reward": mustParseCid("bafk2bzacedmlvtkvxxwooaobiwn4uavxyz3zkfpfrj53t33ir3kssvarl4cek"), + "storagemarket": mustParseCid("bafk2bzacecpnx5ggnegnis3cckhxwl47eckrdv7wfqt2vuw2rpjhxcvlmeimu"), + "storageminer": mustParseCid("bafk2bzaceaelw3s5kdnlpddhyalmp2nb4kiattgg7za3jd7bun4oe6kal2upq"), + "storagepower": mustParseCid("bafk2bzacebyiwuy72ibw4wljlc2css7nciouhg5nwn4sgsbodvhhrfu2vmcwo"), + "system": mustParseCid("bafk2bzaceaid6on264ysr4vpmozxzs2i4nqtntqk3skflu2cbbhwfbpqjem72"), + "verifiedregistry": mustParseCid("bafk2bzaceabaxub3cj3oa266yiu54tezdhk6myfsuwcrlcip5cxsp64p6julu"), + }, }, { Network: "hyperspace", Version: 8, @@ -917,6 +1009,29 @@ var EmbeddedBuiltinActorsMetadata []*BuiltinActorsMetadata = []*BuiltinActorsMet "system": mustParseCid("bafk2bzacecvcqje6kcfqeayj66hezlwzfznytwqkxgw7p64xac5f5lcwjpbwe"), "verifiedregistry": mustParseCid("bafk2bzacecudaqwbz6dukmdbfok7xuxcpjqighnizhxun4spdqvnqgftkupp2"), }, +}, { + Network: "mainnet", + Version: 16, + + ManifestCid: mustParseCid("bafy2bzacedb5sfhrzpd6joitui6wfyjhnfmmojyvlhlmpkhlrhkrh3tmwwb5e"), + Actors: map[string]cid.Cid{ + "account": mustParseCid("bafk2bzacebnxdnkdfl7sabglj7kudj6vnqx5rqw2cypumn5ofsyihmb2jdaxy"), + "cron": mustParseCid("bafk2bzaceap75z4o4buakrybsurk6eqgulmbk7awym33v44cntblffcgi66n6"), + "datacap": mustParseCid("bafk2bzacedo5gtlepdf4il6re3cykxbvixrvn4q3nsxr3tqpsh3r23fox5lye"), + "eam": mustParseCid("bafk2bzacedgqybqpjravyypo5n3kb7wwzis4sn6b6mn6y3pz5ebhb5yiefj5k"), + "ethaccount": mustParseCid("bafk2bzaceckibrqw2o3s2gplxhlnfsaissuwjowzu65wdwyfey4d56mkjcjoi"), + "evm": mustParseCid("bafk2bzacebz5hfooddihwzzguz7df7u3ciyfdeta5ezdeney772emnjsowroo"), + "init": mustParseCid("bafk2bzacecmcb3sskaon6ns5ylq2wxthywh7zelbmzymsqtv45vo5l74ywry2"), + "multisig": mustParseCid("bafk2bzacebqbnin552searxpadxu3xho73xxhmzxu36ssaee2jzt6vwwif66a"), + "paymentchannel": mustParseCid("bafk2bzacebn372vrci26tamd2zla6bf6aai2t5wuthvh3uo6fbfjabqal2j7m"), + "placeholder": mustParseCid("bafk2bzacedfvut2myeleyq67fljcrw4kkmn5pb5dpyozovj7jpoez5irnc3ro"), + "reward": mustParseCid("bafk2bzacebce4sfozugmmfucvkmflyvibh7q7cjsnpgekxzogptece5c62brs"), + "storagemarket": mustParseCid("bafk2bzaceanbda65evztvk4ctgbgvauw7x23eabsig3velz7gzihsncvjxq3y"), + "storageminer": mustParseCid("bafk2bzacea3xgmz5jyffofu4acixumrv2uup5qyirnirwqrp55lgpsjmtkhf4"), + "storagepower": mustParseCid("bafk2bzacea7p7vaqqcwuhw2cx7aytutzqfu6nir3w225b5epku6ypaumpfcr6"), + "system": mustParseCid("bafk2bzacebqdpnpaeob72oxyueufi5ar4iosyfuxmnceig2mpitwgh3vdzsm4"), + "verifiedregistry": mustParseCid("bafk2bzacebw42q6ybguxtyyth76opu62esu2fjlafktk3vub7ngdxbgntm64s"), + }, }, { Network: "testing", Version: 8, @@ -1092,6 +1207,29 @@ var EmbeddedBuiltinActorsMetadata []*BuiltinActorsMetadata = []*BuiltinActorsMet "system": mustParseCid("bafk2bzaceb7zn7sblfs3jterbvzm2cnp4g3ys5yfd3vhatkascrjsidyw74sq"), "verifiedregistry": mustParseCid("bafk2bzaceafcnglgibjq5c26bzoyndzu77g6wdr7s3nnr3wjwhhtvfy7pb5dw"), }, +}, { + Network: "testing", + Version: 16, + + ManifestCid: mustParseCid("bafy2bzaceb4dj3xjtkvqqvmyiktwbme4j5elamg4hhkhs45mgz6fljpbwl7ua"), + Actors: map[string]cid.Cid{ + "account": mustParseCid("bafk2bzaceb5qmjv47xb6voiumm75u2f77peavaseipgibd44hvhla4pf3vsbo"), + "cron": mustParseCid("bafk2bzacec6rpmoek5heiuc47ajw2c26zupuhgvyqllivgxugwuxg6voubx6i"), + "datacap": mustParseCid("bafk2bzacec52hypnxrggpgbx3ldei7m4u7xpqajrrkxk6eysovaydnqdnziga"), + "eam": mustParseCid("bafk2bzacedqlavbjwirjqvi2ov52nzz2iburriq3mbq2lm5uvw2bjbvjbmuog"), + "ethaccount": mustParseCid("bafk2bzaceapp3grhk624a5piaaex7hazbe4o5h7bpz35hhrg3s7cpyje4aaio"), + "evm": mustParseCid("bafk2bzaceboodgpa6xwmyyk7as5izslbdhx5xvsqol65k4e65ird3a7y4acmi"), + "init": mustParseCid("bafk2bzacecdhamabghqrtpbp4l4iyqloyf6truuot25lzkbcag5oh6zxcpnkm"), + "multisig": mustParseCid("bafk2bzaceaf73miahtsdbjbbwpxq4ledsle2y274g3fkhhggutjikdhqrrdd6"), + "paymentchannel": mustParseCid("bafk2bzacedup25gcm3x3ksoinmu2ixszqayfg3htpt4pm3lfxwinhmlm6prby"), + "placeholder": mustParseCid("bafk2bzacedfvut2myeleyq67fljcrw4kkmn5pb5dpyozovj7jpoez5irnc3ro"), + "reward": mustParseCid("bafk2bzacebrngpymy5v6xj6mzkpcjct7t4oafdoeswrc7pl3xnmp2o6vc6hg4"), + "storagemarket": mustParseCid("bafk2bzaced7gq7fn7jlybjjzyljlid7ntwtwbasqhfjqhcakivaa5h3d6243k"), + "storageminer": mustParseCid("bafk2bzaceba7gbwaack3srzgvg3qplb6qhxohnwdcy55awza45ctjsiulf7tq"), + "storagepower": mustParseCid("bafk2bzacedc7d7ar66pg7tkiaa6luv5jujf5wnmiv5ujts3u5daudtass4heu"), + "system": mustParseCid("bafk2bzaceazqpygoyd6az65e5gdopwgc3eas7nz5qrxmegcsxvxrq4nyule64"), + "verifiedregistry": mustParseCid("bafk2bzacebzmntlqv6hyzguur37rt6ercqrymgma7qzariudnogqow2vp6m7w"), + }, }, { Network: "testing-fake-proofs", Version: 8, @@ -1267,6 +1405,29 @@ var EmbeddedBuiltinActorsMetadata []*BuiltinActorsMetadata = []*BuiltinActorsMet "system": mustParseCid("bafk2bzaceb7zn7sblfs3jterbvzm2cnp4g3ys5yfd3vhatkascrjsidyw74sq"), "verifiedregistry": mustParseCid("bafk2bzaceafcnglgibjq5c26bzoyndzu77g6wdr7s3nnr3wjwhhtvfy7pb5dw"), }, +}, { + Network: "testing-fake-proofs", + Version: 16, + + ManifestCid: mustParseCid("bafy2bzaced3bpqm322vi242vuxzhdb6tcchlaxudw2xhg6jczd5ksalz7dclq"), + Actors: map[string]cid.Cid{ + "account": mustParseCid("bafk2bzaceb5qmjv47xb6voiumm75u2f77peavaseipgibd44hvhla4pf3vsbo"), + "cron": mustParseCid("bafk2bzacec6rpmoek5heiuc47ajw2c26zupuhgvyqllivgxugwuxg6voubx6i"), + "datacap": mustParseCid("bafk2bzacec52hypnxrggpgbx3ldei7m4u7xpqajrrkxk6eysovaydnqdnziga"), + "eam": mustParseCid("bafk2bzacedqlavbjwirjqvi2ov52nzz2iburriq3mbq2lm5uvw2bjbvjbmuog"), + "ethaccount": mustParseCid("bafk2bzaceapp3grhk624a5piaaex7hazbe4o5h7bpz35hhrg3s7cpyje4aaio"), + "evm": mustParseCid("bafk2bzaceboodgpa6xwmyyk7as5izslbdhx5xvsqol65k4e65ird3a7y4acmi"), + "init": mustParseCid("bafk2bzacecdhamabghqrtpbp4l4iyqloyf6truuot25lzkbcag5oh6zxcpnkm"), + "multisig": mustParseCid("bafk2bzaceb22qtb77spai4lmkaxkvwugpg2wanp35dxzlnbiva3jty44ec4hi"), + "paymentchannel": mustParseCid("bafk2bzacedup25gcm3x3ksoinmu2ixszqayfg3htpt4pm3lfxwinhmlm6prby"), + "placeholder": mustParseCid("bafk2bzacedfvut2myeleyq67fljcrw4kkmn5pb5dpyozovj7jpoez5irnc3ro"), + "reward": mustParseCid("bafk2bzacebrngpymy5v6xj6mzkpcjct7t4oafdoeswrc7pl3xnmp2o6vc6hg4"), + "storagemarket": mustParseCid("bafk2bzaced7gq7fn7jlybjjzyljlid7ntwtwbasqhfjqhcakivaa5h3d6243k"), + "storageminer": mustParseCid("bafk2bzacedsa2saihoa3ehfwpqba6bhzjpmv3xudfocneoffzjcncjwcvama4"), + "storagepower": mustParseCid("bafk2bzacedc7d7ar66pg7tkiaa6luv5jujf5wnmiv5ujts3u5daudtass4heu"), + "system": mustParseCid("bafk2bzaceazqpygoyd6az65e5gdopwgc3eas7nz5qrxmegcsxvxrq4nyule64"), + "verifiedregistry": mustParseCid("bafk2bzacebzmntlqv6hyzguur37rt6ercqrymgma7qzariudnogqow2vp6m7w"), + }, }} func mustParseCid(c string) cid.Cid { diff --git a/venus-shared/actors/policy/policy.go b/venus-shared/actors/policy/policy.go index 2863c9da12..275ddfe340 100644 --- a/venus-shared/actors/policy/policy.go +++ b/venus-shared/actors/policy/policy.go @@ -95,18 +95,23 @@ import ( miner15 "github.com/filecoin-project/go-state-types/builtin/v15/miner" verifreg15 "github.com/filecoin-project/go-state-types/builtin/v15/verifreg" - paych15 "github.com/filecoin-project/go-state-types/builtin/v15/paych" + builtin16 "github.com/filecoin-project/go-state-types/builtin" + market16 "github.com/filecoin-project/go-state-types/builtin/v16/market" + miner16 "github.com/filecoin-project/go-state-types/builtin/v16/miner" + verifreg16 "github.com/filecoin-project/go-state-types/builtin/v16/verifreg" + + paych16 "github.com/filecoin-project/go-state-types/builtin/v16/paych" ) const ( - ChainFinality = miner15.ChainFinality + ChainFinality = miner16.ChainFinality SealRandomnessLookback = ChainFinality - PaychSettleDelay = paych15.SettleDelay - MaxPreCommitRandomnessLookback = builtin15.EpochsInDay + SealRandomnessLookback + PaychSettleDelay = paych16.SettleDelay + MaxPreCommitRandomnessLookback = builtin16.EpochsInDay + SealRandomnessLookback ) var ( - MarketDefaultAllocationTermBuffer = market15.MarketDefaultAllocationTermBuffer + MarketDefaultAllocationTermBuffer = market16.MarketDefaultAllocationTermBuffer ) // SetSupportedProofTypes sets supported proof types, across all actor versions. @@ -227,11 +232,13 @@ func SetPreCommitChallengeDelay(delay abi.ChainEpoch) { miner15.PreCommitChallengeDelay = delay + miner16.PreCommitChallengeDelay = delay + } func GetPreCommitChallengeDelay() abi.ChainEpoch { // TODO: this function shouldn't really exist. Instead, the API should expose the precommit delay. - return miner15.PreCommitChallengeDelay + return miner16.PreCommitChallengeDelay } // SetConsensusMinerMinPower sets the minimum power of an individual miner must @@ -297,6 +304,10 @@ func SetConsensusMinerMinPower(p abi.StoragePower) { policy.ConsensusMinerMinPower = p } + for _, policy := range builtin16.PoStProofPolicies { + policy.ConsensusMinerMinPower = p + } + } // SetMinVerifiedDealSize sets the minimum size of a verified deal. This should @@ -333,6 +344,8 @@ func SetMinVerifiedDealSize(size abi.StoragePower) { verifreg15.MinVerifiedDealSize = size + verifreg16.MinVerifiedDealSize = size + } func GetMaxProveCommitDuration(ver actorstypes.Version, t abi.RegisteredSealProof) (abi.ChainEpoch, error) { @@ -398,6 +411,10 @@ func GetMaxProveCommitDuration(ver actorstypes.Version, t abi.RegisteredSealProo return miner15.MaxProveCommitDuration[t], nil + case actorstypes.Version16: + + return miner16.MaxProveCommitDuration[t], nil + default: return 0, fmt.Errorf("unsupported actors version") } @@ -478,6 +495,11 @@ func SetProviderCollateralSupplyTarget(num, denom big.Int) { Denominator: denom, } + market16.ProviderCollateralSupplyTarget = builtin16.BigFrac{ + Numerator: num, + Denominator: denom, + } + } func DealProviderCollateralBounds( @@ -566,13 +588,18 @@ func DealProviderCollateralBounds( min, max := market15.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil) return min, max, nil + case actorstypes.Version16: + + min, max := market16.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil) + return min, max, nil + default: return big.Zero(), big.Zero(), fmt.Errorf("unsupported actors version") } } func DealDurationBounds(pieceSize abi.PaddedPieceSize) (min, max abi.ChainEpoch) { - return market15.DealDurationBounds(pieceSize) + return market16.DealDurationBounds(pieceSize) } // SetWPoStChallengeWindow sets the challenge window and scales the proving period to match (such @@ -676,6 +703,13 @@ func SetWPoStChallengeWindow(period abi.ChainEpoch) { // scale it if we're scaling the challenge period. miner15.WPoStDisputeWindow = period * 30 + miner16.WPoStChallengeWindow = period + miner16.WPoStProvingPeriod = period * abi.ChainEpoch(miner16.WPoStPeriodDeadlines) + + // by default, this is 2x finality which is 30 periods. + // scale it if we're scaling the challenge period. + miner16.WPoStDisputeWindow = period * 30 + } func GetWinningPoStSectorSetLookback(nwVer network.Version) abi.ChainEpoch { @@ -739,6 +773,9 @@ func GetMaxSectorExpirationExtension(nv network.Version) (abi.ChainEpoch, error) case actorstypes.Version15: return miner15.MaxSectorExpirationExtension, nil + case actorstypes.Version16: + return miner16.MaxSectorExpirationExtension, nil + default: return 0, fmt.Errorf("unsupported network version") } @@ -746,11 +783,11 @@ func GetMaxSectorExpirationExtension(nv network.Version) (abi.ChainEpoch, error) } func GetMinSectorExpiration() abi.ChainEpoch { - return miner15.MinSectorExpiration + return miner16.MinSectorExpiration } func GetMaxPoStPartitions(nv network.Version, p abi.RegisteredPoStProof) (int, error) { - sectorsPerPart, err := builtin15.PoStProofWindowPoStPartitionSectors(p) + sectorsPerPart, err := builtin16.PoStProofWindowPoStPartitionSectors(p) if err != nil { return 0, err } @@ -759,7 +796,7 @@ func GetMaxPoStPartitions(nv network.Version, p abi.RegisteredPoStProof) (int, e return 0, err } - return min(miner15.PoStedPartitionsMax, int(uint64(maxSectors)/sectorsPerPart)), nil + return min(miner16.PoStedPartitionsMax, int(uint64(maxSectors)/sectorsPerPart)), nil } func GetDefaultAggregationProof() abi.RegisteredAggregationProof { @@ -771,7 +808,7 @@ func GetSectorMaxLifetime(proof abi.RegisteredSealProof, nwVer network.Version) return builtin4.SealProofPoliciesV0[proof].SectorMaxLifetime } - return builtin15.SealProofPoliciesV11[proof].SectorMaxLifetime + return builtin16.SealProofPoliciesV11[proof].SectorMaxLifetime } func GetAddressedSectorsMax(nwVer network.Version) (int, error) { @@ -826,6 +863,9 @@ func GetAddressedSectorsMax(nwVer network.Version) (int, error) { case actorstypes.Version15: return miner15.AddressedSectorsMax, nil + case actorstypes.Version16: + return miner16.AddressedSectorsMax, nil + default: return 0, fmt.Errorf("unsupported network version") } @@ -899,6 +939,10 @@ func GetDeclarationsMax(nwVer network.Version) (int, error) { return miner15.DeclarationsMax, nil + case actorstypes.Version16: + + return miner16.DeclarationsMax, nil + default: return 0, fmt.Errorf("unsupported network version") } @@ -971,6 +1015,10 @@ func AggregateProveCommitNetworkFee(nwVer network.Version, aggregateSize int, ba return miner15.AggregateProveCommitNetworkFee(aggregateSize, baseFee), nil + case actorstypes.Version16: + + return miner16.AggregateProveCommitNetworkFee(aggregateSize, baseFee), nil + default: return big.Zero(), fmt.Errorf("unsupported network version") } @@ -1043,6 +1091,10 @@ func AggregatePreCommitNetworkFee(nwVer network.Version, aggregateSize int, base return miner15.AggregatePreCommitNetworkFee(aggregateSize, baseFee), nil + case actorstypes.Version16: + + return miner16.AggregatePreCommitNetworkFee(aggregateSize, baseFee), nil + default: return big.Zero(), fmt.Errorf("unsupported network version") } diff --git a/venus-shared/actors/version.go b/venus-shared/actors/version.go index 15aadbf864..f6aa7990e4 100644 --- a/venus-shared/actors/version.go +++ b/venus-shared/actors/version.go @@ -16,9 +16,9 @@ const ({{range .actorVersions}} /* inline-gen start */ -var LatestVersion = 15 +var LatestVersion = 16 -var Versions = []int{0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15} +var Versions = []int{0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16} const ( Version0 Version = 0 @@ -36,6 +36,7 @@ const ( Version13 Version = 13 Version14 Version = 14 Version15 Version = 15 + Version16 Version = 16 ) /* inline-gen end */ diff --git a/venus-shared/api/chain/v0/method.md b/venus-shared/api/chain/v0/method.md index 75bd9fe55a..bdf6747c74 100644 --- a/venus-shared/api/chain/v0/method.md +++ b/venus-shared/api/chain/v0/method.md @@ -1223,7 +1223,7 @@ Perms: read Inputs: ```json [ - 24 + 25 ] ``` @@ -1238,7 +1238,7 @@ Perms: read Inputs: ```json [ - 24 + 25 ] ``` @@ -1664,7 +1664,8 @@ Response: "UpgradeDragonHeight": 10101, "UpgradePhoenixHeight": 10101, "UpgradeWaffleHeight": 10101, - "UpgradeTuktukHeight": 10101 + "UpgradeTuktukHeight": 10101, + "UpgradeTeepHeight": 10101 }, "Eip155ChainID": 123 } @@ -1782,7 +1783,7 @@ Inputs: ] ``` -Response: `24` +Response: `25` ### StateReplay diff --git a/venus-shared/api/chain/v1/chain.go b/venus-shared/api/chain/v1/chain.go index e145ca8f86..c589a80540 100644 --- a/venus-shared/api/chain/v1/chain.go +++ b/venus-shared/api/chain/v1/chain.go @@ -156,6 +156,8 @@ type IChainInfo interface { // Messages in the `apply` parameter must have the correct nonces, and gas // values set. StateCompute(context.Context, abi.ChainEpoch, []*types.Message, types.TipSetKey) (*types.ComputeStateOutput, error) //perm:read + // StateMarketProposalPending returns whether a given proposal CID is marked as pending in the market actor + StateMarketProposalPending(ctx context.Context, proposalCid cid.Cid, tsk types.TipSetKey) (bool, error) //perm:read } type IMinerState interface { diff --git a/venus-shared/api/chain/v1/method.md b/venus-shared/api/chain/v1/method.md index b06f1884df..79b681da40 100644 --- a/venus-shared/api/chain/v1/method.md +++ b/venus-shared/api/chain/v1/method.md @@ -56,6 +56,7 @@ curl http://:/rpc/v1 -X POST -H "Content-Type: application/json" -H " * [StateGetRandomnessDigestFromTickets](#stategetrandomnessdigestfromtickets) * [StateGetRandomnessFromBeacon](#stategetrandomnessfrombeacon) * [StateGetRandomnessFromTickets](#stategetrandomnessfromtickets) + * [StateMarketProposalPending](#statemarketproposalpending) * [StateNetworkName](#statenetworkname) * [StateNetworkVersion](#statenetworkversion) * [StateReplay](#statereplay) @@ -1414,7 +1415,7 @@ Perms: read Inputs: ```json [ - 24 + 25 ] ``` @@ -1429,7 +1430,7 @@ Perms: read Inputs: ```json [ - 24 + 25 ] ``` @@ -1879,7 +1880,8 @@ Response: "UpgradeDragonHeight": 10101, "UpgradePhoenixHeight": 10101, "UpgradeWaffleHeight": 10101, - "UpgradeTuktukHeight": 10101 + "UpgradeTuktukHeight": 10101, + "UpgradeTeepHeight": 10101 }, "Eip155ChainID": 123 } @@ -1979,6 +1981,31 @@ Inputs: Response: `"Bw=="` +### StateMarketProposalPending +StateMarketProposalPending returns whether a given proposal CID is marked as pending in the market actor + + +Perms: read + +Inputs: +```json +[ + { + "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" + }, + [ + { + "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" + }, + { + "/": "bafy2bzacebp3shtrn43k7g3unredz7fxn4gj533d3o43tqn2p2ipxxhrvchve" + } + ] +] +``` + +Response: `true` + ### StateNetworkName @@ -2007,7 +2034,7 @@ Inputs: ] ``` -Response: `24` +Response: `25` ### StateReplay diff --git a/venus-shared/api/chain/v1/mock/mock_fullnode.go b/venus-shared/api/chain/v1/mock/mock_fullnode.go index 32cdd84e26..76a57aafd4 100644 --- a/venus-shared/api/chain/v1/mock/mock_fullnode.go +++ b/venus-shared/api/chain/v1/mock/mock_fullnode.go @@ -2979,6 +2979,21 @@ func (mr *MockFullNodeMockRecorder) StateMarketParticipants(arg0, arg1 interface return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateMarketParticipants", reflect.TypeOf((*MockFullNode)(nil).StateMarketParticipants), arg0, arg1) } +// StateMarketProposalPending mocks base method. +func (m *MockFullNode) StateMarketProposalPending(arg0 context.Context, arg1 cid.Cid, arg2 types0.TipSetKey) (bool, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "StateMarketProposalPending", arg0, arg1, arg2) + ret0, _ := ret[0].(bool) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// StateMarketProposalPending indicates an expected call of StateMarketProposalPending. +func (mr *MockFullNodeMockRecorder) StateMarketProposalPending(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateMarketProposalPending", reflect.TypeOf((*MockFullNode)(nil).StateMarketProposalPending), arg0, arg1, arg2) +} + // StateMarketStorageDeal mocks base method. func (m *MockFullNode) StateMarketStorageDeal(arg0 context.Context, arg1 abi.DealID, arg2 types0.TipSetKey) (*types0.MarketDeal, error) { m.ctrl.T.Helper() diff --git a/venus-shared/api/chain/v1/proxy_gen.go b/venus-shared/api/chain/v1/proxy_gen.go index a8787434df..4be5da41d2 100644 --- a/venus-shared/api/chain/v1/proxy_gen.go +++ b/venus-shared/api/chain/v1/proxy_gen.go @@ -314,6 +314,7 @@ type IChainInfoStruct struct { StateGetRandomnessDigestFromTickets func(ctx context.Context, randEpoch abi.ChainEpoch, tsk types.TipSetKey) (abi.Randomness, error) `perm:"read"` StateGetRandomnessFromBeacon func(ctx context.Context, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte, tsk types.TipSetKey) (abi.Randomness, error) `perm:"read"` StateGetRandomnessFromTickets func(ctx context.Context, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte, tsk types.TipSetKey) (abi.Randomness, error) `perm:"read"` + StateMarketProposalPending func(ctx context.Context, proposalCid cid.Cid, tsk types.TipSetKey) (bool, error) `perm:"read"` StateNetworkName func(ctx context.Context) (types.NetworkName, error) `perm:"read"` StateNetworkVersion func(ctx context.Context, tsk types.TipSetKey) (network.Version, error) `perm:"read"` StateReplay func(context.Context, types.TipSetKey, cid.Cid) (*types.InvocResult, error) `perm:"read"` @@ -430,6 +431,9 @@ func (s *IChainInfoStruct) StateGetRandomnessFromBeacon(p0 context.Context, p1 c func (s *IChainInfoStruct) StateGetRandomnessFromTickets(p0 context.Context, p1 crypto.DomainSeparationTag, p2 abi.ChainEpoch, p3 []byte, p4 types.TipSetKey) (abi.Randomness, error) { return s.Internal.StateGetRandomnessFromTickets(p0, p1, p2, p3, p4) } +func (s *IChainInfoStruct) StateMarketProposalPending(p0 context.Context, p1 cid.Cid, p2 types.TipSetKey) (bool, error) { + return s.Internal.StateMarketProposalPending(p0, p1, p2) +} func (s *IChainInfoStruct) StateNetworkName(p0 context.Context) (types.NetworkName, error) { return s.Internal.StateNetworkName(p0) } diff --git a/venus-shared/api/gateway/v1/method.md b/venus-shared/api/gateway/v1/method.md index 79e9224ff3..2d98a07b67 100644 --- a/venus-shared/api/gateway/v1/method.md +++ b/venus-shared/api/gateway/v1/method.md @@ -205,7 +205,7 @@ Inputs: ], "Bw==", 10101, - 24 + 25 ] ``` diff --git a/venus-shared/api/gateway/v2/method.md b/venus-shared/api/gateway/v2/method.md index 2d0f4589fc..f7a890f330 100644 --- a/venus-shared/api/gateway/v2/method.md +++ b/venus-shared/api/gateway/v2/method.md @@ -174,7 +174,7 @@ Inputs: ], "Bw==", 10101, - 24 + 25 ] ``` diff --git a/venus-shared/compatible-checks/actor-sources.txt b/venus-shared/compatible-checks/actor-sources.txt index 903292804a..2003cc49df 100644 --- a/venus-shared/compatible-checks/actor-sources.txt +++ b/venus-shared/compatible-checks/actor-sources.txt @@ -16,6 +16,7 @@ SOURCES IN chain/actors: builtin/account/v13.go builtin/account/v14.go builtin/account/v15.go + builtin/account/v16.go builtin/account/v2.go builtin/account/v3.go builtin/account/v4.go @@ -33,6 +34,7 @@ SOURCES IN chain/actors: builtin/cron/v13.go builtin/cron/v14.go builtin/cron/v15.go + builtin/cron/v16.go builtin/cron/v2.go builtin/cron/v3.go builtin/cron/v4.go @@ -49,6 +51,7 @@ SOURCES IN chain/actors: builtin/datacap/v13.go builtin/datacap/v14.go builtin/datacap/v15.go + builtin/datacap/v16.go builtin/datacap/v9.go builtin/evm/evm.go builtin/evm/v10.go @@ -57,6 +60,7 @@ SOURCES IN chain/actors: builtin/evm/v13.go builtin/evm/v14.go builtin/evm/v15.go + builtin/evm/v16.go builtin/init/diff.go builtin/init/init.go builtin/init/v0.go @@ -66,6 +70,7 @@ SOURCES IN chain/actors: builtin/init/v13.go builtin/init/v14.go builtin/init/v15.go + builtin/init/v16.go builtin/init/v2.go builtin/init/v3.go builtin/init/v4.go @@ -83,6 +88,7 @@ SOURCES IN chain/actors: builtin/market/v13.go builtin/market/v14.go builtin/market/v15.go + builtin/market/v16.go builtin/market/v2.go builtin/market/v3.go builtin/market/v4.go @@ -102,6 +108,7 @@ SOURCES IN chain/actors: builtin/miner/v13.go builtin/miner/v14.go builtin/miner/v15.go + builtin/miner/v16.go builtin/miner/v2.go builtin/miner/v3.go builtin/miner/v4.go @@ -118,6 +125,7 @@ SOURCES IN chain/actors: builtin/multisig/message13.go builtin/multisig/message14.go builtin/multisig/message15.go + builtin/multisig/message16.go builtin/multisig/message2.go builtin/multisig/message3.go builtin/multisig/message4.go @@ -134,6 +142,7 @@ SOURCES IN chain/actors: builtin/multisig/v13.go builtin/multisig/v14.go builtin/multisig/v15.go + builtin/multisig/v16.go builtin/multisig/v2.go builtin/multisig/v3.go builtin/multisig/v4.go @@ -149,6 +158,7 @@ SOURCES IN chain/actors: builtin/paych/message13.go builtin/paych/message14.go builtin/paych/message15.go + builtin/paych/message16.go builtin/paych/message2.go builtin/paych/message3.go builtin/paych/message4.go @@ -166,6 +176,7 @@ SOURCES IN chain/actors: builtin/paych/v13.go builtin/paych/v14.go builtin/paych/v15.go + builtin/paych/v16.go builtin/paych/v2.go builtin/paych/v3.go builtin/paych/v4.go @@ -183,6 +194,7 @@ SOURCES IN chain/actors: builtin/power/v13.go builtin/power/v14.go builtin/power/v15.go + builtin/power/v16.go builtin/power/v2.go builtin/power/v3.go builtin/power/v4.go @@ -200,6 +212,7 @@ SOURCES IN chain/actors: builtin/reward/v13.go builtin/reward/v14.go builtin/reward/v15.go + builtin/reward/v16.go builtin/reward/v2.go builtin/reward/v3.go builtin/reward/v4.go @@ -216,6 +229,7 @@ SOURCES IN chain/actors: builtin/system/v13.go builtin/system/v14.go builtin/system/v15.go + builtin/system/v16.go builtin/system/v2.go builtin/system/v3.go builtin/system/v4.go @@ -232,6 +246,7 @@ SOURCES IN chain/actors: builtin/verifreg/v13.go builtin/verifreg/v14.go builtin/verifreg/v15.go + builtin/verifreg/v16.go builtin/verifreg/v2.go builtin/verifreg/v3.go builtin/verifreg/v4.go diff --git a/venus-shared/compatible-checks/api-checksum.txt b/venus-shared/compatible-checks/api-checksum.txt index 959e0d9ef8..cbc5303d39 100644 --- a/venus-shared/compatible-checks/api-checksum.txt +++ b/venus-shared/compatible-checks/api-checksum.txt @@ -418,6 +418,7 @@ api.FullNode: StateMarketBalance: In=3, Out=2, CheckSum=bbab976bd25166200f737c94fc970bc7 StateMarketDeals: In=2, Out=2, CheckSum=46b5eef922e8252939bf00e1e80ae89e StateMarketParticipants: In=2, Out=2, CheckSum=acc9019d0b6e389743c6f992350f407c + StateMarketProposalPending: In=3, Out=2, CheckSum=fbb29a0d0f9a5fe4d3149de39b8f07c0 StateMarketStorageDeal: In=3, Out=2, CheckSum=94af302d39beba9f0ce7648f4118b6aa StateMinerActiveSectors: In=3, Out=2, CheckSum=6dc03bd9f54d60f68a2dd9790a6490a3 StateMinerAllocated: In=3, Out=2, CheckSum=808e4357d56c3d08769a9d7a249ea7c0 diff --git a/venus-shared/types/api_types.go b/venus-shared/types/api_types.go index 36c6e0087a..54cdd574fd 100644 --- a/venus-shared/types/api_types.go +++ b/venus-shared/types/api_types.go @@ -9,6 +9,7 @@ import ( gpbft "github.com/filecoin-project/go-f3/gpbft" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" + exitcode "github.com/filecoin-project/go-state-types/exitcode" "github.com/ipfs/go-cid" pubsub "github.com/libp2p/go-libp2p-pubsub" "github.com/libp2p/go-libp2p/core/peer" @@ -480,6 +481,7 @@ type ForkUpgradeParams struct { UpgradePhoenixHeight abi.ChainEpoch UpgradeWaffleHeight abi.ChainEpoch UpgradeTuktukHeight abi.ChainEpoch + UpgradeTeepHeight abi.ChainEpoch } type NodeStatus struct { @@ -567,6 +569,8 @@ var ( _ error = (*errF3ParticipationTicketExpired)(nil) _ error = (*errF3ParticipationIssuerMismatch)(nil) _ error = (*errF3NotReady)(nil) + _ error = (*ErrExecutionReverted)(nil) + _ error = (*ErrNullRound)(nil) ) // ErrOutOfGas signals that a call failed due to insufficient gas. @@ -608,3 +612,43 @@ func (errF3ParticipationTicketStartBeforeExisting) Error() string { type errF3NotReady struct{} func (errF3NotReady) Error() string { return "f3 isn't yet ready to participate" } + +// ErrExecutionReverted is used to return execution reverted with a reason for a revert in the `data` field. +type ErrExecutionReverted struct { + Message string + Data string +} + +// Error returns the error message. +func (e *ErrExecutionReverted) Error() string { return e.Message } + +// NewErrExecutionReverted creates a new ErrExecutionReverted with the given reason. +func NewErrExecutionReverted(exitCode exitcode.ExitCode, error, reason string, data []byte) *ErrExecutionReverted { + return &ErrExecutionReverted{ + Message: fmt.Sprintf("message execution failed (exit=[%s], revert reason=[%s], vm error=[%s])", exitCode, reason, error), + Data: fmt.Sprintf("0x%x", data), + } +} + +type ErrNullRound struct { + Epoch abi.ChainEpoch + Message string +} + +func NewErrNullRound(epoch abi.ChainEpoch) *ErrNullRound { + return &ErrNullRound{ + Epoch: epoch, + Message: fmt.Sprintf("requested epoch was a null round (%d)", epoch), + } +} + +func (e *ErrNullRound) Error() string { + return e.Message +} + +// Is performs a non-strict type check, we only care if the target is an ErrNullRound +// and will ignore the contents (specifically there is no matching on Epoch). +func (e *ErrNullRound) Is(target error) bool { + _, ok := target.(*ErrNullRound) + return ok +} diff --git a/venus-shared/utils/method_map.go b/venus-shared/utils/method_map.go index 1f5d2c84f2..190857f831 100644 --- a/venus-shared/utils/method_map.go +++ b/venus-shared/utils/method_map.go @@ -63,6 +63,7 @@ func loadMethodsMap() { actors = append(actors, actorsWithVersion{av: actorstypes.Version13, actors: builtin.MakeRegistry(actorstypes.Version13)}) actors = append(actors, actorsWithVersion{av: actorstypes.Version14, actors: builtin.MakeRegistry(actorstypes.Version14)}) actors = append(actors, actorsWithVersion{av: actorstypes.Version15, actors: builtin.MakeRegistry(actorstypes.Version15)}) + actors = append(actors, actorsWithVersion{av: actorstypes.Version16, actors: builtin.MakeRegistry(actorstypes.Version16)}) for _, awv := range actors { for _, actor := range awv.actors {