From 3c87d38a4829460c92a084465521f649d7613796 Mon Sep 17 00:00:00 2001 From: ZenGround0 <5515260+ZenGround0@users.noreply.github.com> Date: Fri, 25 Mar 2022 13:56:39 -0600 Subject: [PATCH] Fix PRU multi dline bug (#1582) Co-authored-by: zenground0 --- actors/builtin/miner/miner_actor.go | 9 ++++---- actors/test/replica_update_test.go | 34 ++++++++++++++++++++++++----- test-vectors/determinism-check | 2 +- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/actors/builtin/miner/miner_actor.go b/actors/builtin/miner/miner_actor.go index 63d4b03f5..fb0402712 100644 --- a/actors/builtin/miner/miner_actor.go +++ b/actors/builtin/miner/miner_actor.go @@ -4,9 +4,10 @@ import ( "bytes" "encoding/binary" "fmt" - miner7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/miner" "math" + miner7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/miner" + addr "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-state-types/abi" @@ -2229,7 +2230,7 @@ func (a Actor) ProveReplicaUpdates(rt Runtime, params *ProveReplicaUpdatesParams deadlines, err := st.LoadDeadlines(store) builtin.RequireNoErr(rt, err, exitcode.ErrIllegalState, "failed to load deadlines") - newSectors := make([]*SectorOnChainInfo, len(validatedUpdates)) + newSectors := make([]*SectorOnChainInfo, 0) for _, dlIdx := range deadlinesToLoad { deadline, err := deadlines.LoadDeadline(store, dlIdx) builtin.RequireNoErr(rt, err, exitcode.ErrIllegalState, "failed to load deadline %d", dlIdx) @@ -2239,7 +2240,7 @@ func (a Actor) ProveReplicaUpdates(rt Runtime, params *ProveReplicaUpdatesParams quant := st.QuantSpecForDeadline(dlIdx) - for i, updateWithDetails := range declsByDeadline[dlIdx] { + for _, updateWithDetails := range declsByDeadline[dlIdx] { updateProofType, err := updateWithDetails.sectorInfo.SealProof.RegisteredUpdateProof() builtin.RequireNoErr(rt, err, exitcode.ErrIllegalState, "couldn't load update proof type") builtin.RequirePredicate(rt, updateWithDetails.update.UpdateProofType == updateProofType, exitcode.ErrIllegalArgument, "unsupported update proof type %d", updateWithDetails.update.UpdateProofType) @@ -2321,7 +2322,7 @@ func (a Actor) ProveReplicaUpdates(rt Runtime, params *ProveReplicaUpdatesParams updateWithDetails.update.Deadline, updateWithDetails.update.Partition) - newSectors[i] = &newSectorInfo + newSectors = append(newSectors, &newSectorInfo) succeededSectors.Set(uint64(newSectorInfo.SectorNumber)) } diff --git a/actors/test/replica_update_test.go b/actors/test/replica_update_test.go index 10cfcb51f..1106b9d48 100644 --- a/actors/test/replica_update_test.go +++ b/actors/test/replica_update_test.go @@ -578,9 +578,6 @@ func TestWrongPartitionIndexFailure(t *testing.T) { require.NotEqual(t, replicaUpdate.NewSealedSectorCID, newSectorInfo.SealedCID) } -// This test demonstrates a bug introduced in network v15. When this bug is fixed -// this test should be modified so that the final ProveReplicaUpdate call is asserted -// to pass instead of fail with `exitcode.ErrIllegalState` func TestProveReplicaUpdateMultiDline(t *testing.T) { ctx := context.Background() blkStore := ipld.NewBlockStoreInMemory() @@ -642,6 +639,9 @@ func TestProveReplicaUpdateMultiDline(t *testing.T) { require.True(t, vm.CheckSectorActive(t, v, minerAddrs.IDAddress, currDlInfo.Index, 0, firstSectorNumberP2)) /* Replica Update across two deadlines */ + oldSectorCommRP1 := vm.SectorInfo(t, v, minerAddrs.RobustAddress, firstSectorNumberP1).SealedCID + oldSectorCommRP2 := vm.SectorInfo(t, v, minerAddrs.RobustAddress, firstSectorNumberP2).SealedCID + dealIDs := createDeals(t, 2, v, worker, worker, minerAddrs.IDAddress, sealProof) replicaUpdate1 := miner.ReplicaUpdate{ SectorID: firstSectorNumberP1, @@ -662,10 +662,32 @@ func TestProveReplicaUpdateMultiDline(t *testing.T) { } // When this bug is fixed this should become vm.ApplyOk - vm.ApplyCode(t, v, addrs[0], minerAddrs.RobustAddress, big.Zero(), + ret := vm.ApplyOk(t, v, addrs[0], minerAddrs.RobustAddress, big.Zero(), builtin.MethodsMiner.ProveReplicaUpdates, - &miner.ProveReplicaUpdatesParams{Updates: []miner.ReplicaUpdate{replicaUpdate1, replicaUpdate2}}, - exitcode.ErrIllegalState) + &miner.ProveReplicaUpdatesParams{Updates: []miner.ReplicaUpdate{replicaUpdate1, replicaUpdate2}}) + + updatedSectors, ok := ret.(*bitfield.BitField) + require.True(t, ok) + count, err := updatedSectors.Count() + require.NoError(t, err) + require.Equal(t, uint64(2), count) + + isSet, err := updatedSectors.IsSet(uint64(firstSectorNumberP1)) + require.NoError(t, err) + require.True(t, isSet) + + isSet, err = updatedSectors.IsSet(uint64(firstSectorNumberP2)) + require.NoError(t, err) + require.True(t, isSet) + + newSectorInfoP1 := vm.SectorInfo(t, v, minerAddrs.RobustAddress, firstSectorNumberP1) + require.Equal(t, dealIDs[0], newSectorInfoP1.DealIDs[0]) + require.Equal(t, oldSectorCommRP1, *newSectorInfoP1.SectorKeyCID) + require.Equal(t, replicaUpdate1.NewSealedSectorCID, newSectorInfoP1.SealedCID) + newSectorInfoP2 := vm.SectorInfo(t, v, minerAddrs.RobustAddress, firstSectorNumberP2) + require.Equal(t, dealIDs[1], newSectorInfoP2.DealIDs[0]) + require.Equal(t, oldSectorCommRP2, *newSectorInfoP2.SectorKeyCID) + require.Equal(t, replicaUpdate2.NewSealedSectorCID, newSectorInfoP2.SealedCID) } func TestDealIncludedInMultipleSectors(t *testing.T) { diff --git a/test-vectors/determinism-check b/test-vectors/determinism-check index 85a20cff8..5232e5a10 100644 --- a/test-vectors/determinism-check +++ b/test-vectors/determinism-check @@ -1 +1 @@ -- e4d6d552f6904b51d3ba21ca3fbee236dd2d7c2eb5fbc4a36bb2117fd76ffd04 +- 23bbe54067d78d54842057fe9f0b390ecb567d79602f08881c7e2b205300e13a