Skip to content
This repository has been archived by the owner on Jun 6, 2023. It is now read-only.

Commit

Permalink
Fix PRU multi dline bug (#1582)
Browse files Browse the repository at this point in the history
Co-authored-by: zenground0 <[email protected]>
  • Loading branch information
ZenGround0 and ZenGround0 authored Mar 25, 2022
1 parent d56b240 commit 3c87d38
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
9 changes: 5 additions & 4 deletions actors/builtin/miner/miner_actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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))
}

Expand Down
34 changes: 28 additions & 6 deletions actors/test/replica_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion test-vectors/determinism-check
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- e4d6d552f6904b51d3ba21ca3fbee236dd2d7c2eb5fbc4a36bb2117fd76ffd04
- 23bbe54067d78d54842057fe9f0b390ecb567d79602f08881c7e2b205300e13a

0 comments on commit 3c87d38

Please sign in to comment.