test evil post on recover
This commit is contained in:
parent
cc423ee4d2
commit
9e611d5f4d
@ -17,6 +17,7 @@ import (
|
|||||||
"github.com/filecoin-project/go-bitfield"
|
"github.com/filecoin-project/go-bitfield"
|
||||||
"github.com/filecoin-project/go-state-types/abi"
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
"github.com/filecoin-project/go-state-types/crypto"
|
"github.com/filecoin-project/go-state-types/crypto"
|
||||||
|
"github.com/filecoin-project/go-state-types/dline"
|
||||||
"github.com/filecoin-project/go-state-types/network"
|
"github.com/filecoin-project/go-state-types/network"
|
||||||
"github.com/filecoin-project/lotus/extern/sector-storage/mock"
|
"github.com/filecoin-project/lotus/extern/sector-storage/mock"
|
||||||
sealing "github.com/filecoin-project/lotus/extern/storage-sealing"
|
sealing "github.com/filecoin-project/lotus/extern/storage-sealing"
|
||||||
@ -641,6 +642,9 @@ func TestWindowPostDispute(t *testing.T, b APIBuilder, blocktime time.Duration)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defaultFrom, err := client.WalletDefaultAddress(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
build.Clock.Sleep(time.Second)
|
build.Clock.Sleep(time.Second)
|
||||||
|
|
||||||
// Mine with the _second_ node (the good one).
|
// Mine with the _second_ node (the good one).
|
||||||
@ -675,9 +679,6 @@ func TestWindowPostDispute(t *testing.T, b APIBuilder, blocktime time.Duration)
|
|||||||
di, err := client.StateMinerProvingDeadline(ctx, evilMinerAddr, types.EmptyTSK)
|
di, err := client.StateMinerProvingDeadline(ctx, evilMinerAddr, types.EmptyTSK)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
minerInfo, err := client.StateMinerInfo(ctx, evilMinerAddr, types.EmptyTSK)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
fmt.Printf("Running one proving period\n")
|
fmt.Printf("Running one proving period\n")
|
||||||
fmt.Printf("End for head.Height > %d\n", di.PeriodStart+di.WPoStProvingPeriod*2)
|
fmt.Printf("End for head.Height > %d\n", di.PeriodStart+di.WPoStProvingPeriod*2)
|
||||||
|
|
||||||
@ -724,47 +725,8 @@ func TestWindowPostDispute(t *testing.T, b APIBuilder, blocktime time.Duration)
|
|||||||
build.Clock.Sleep(blocktime)
|
build.Clock.Sleep(blocktime)
|
||||||
}
|
}
|
||||||
|
|
||||||
// submit a bad proof
|
err = submitBadProof(ctx, client, evilMinerAddr, di, evilSectorLoc.Deadline, evilSectorLoc.Partition)
|
||||||
{
|
require.NoError(t, err, "evil proof not accepted")
|
||||||
fmt.Println("submitting evil proof")
|
|
||||||
head, err := client.ChainHead(ctx)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
commEpoch := di.Open
|
|
||||||
commRand, err := client.ChainGetRandomnessFromTickets(
|
|
||||||
ctx, head.Key(), crypto.DomainSeparationTag_PoStChainCommit,
|
|
||||||
commEpoch, nil,
|
|
||||||
)
|
|
||||||
require.NoError(t, err)
|
|
||||||
params := &miner.SubmitWindowedPoStParams{
|
|
||||||
ChainCommitEpoch: commEpoch,
|
|
||||||
ChainCommitRand: commRand,
|
|
||||||
Deadline: evilSectorLoc.Deadline,
|
|
||||||
Partitions: []miner.PoStPartition{{Index: evilSectorLoc.Partition}},
|
|
||||||
Proofs: []proof3.PoStProof{{
|
|
||||||
PoStProof: minerInfo.WindowPoStProofType,
|
|
||||||
ProofBytes: []byte("I'm soooo very evil."),
|
|
||||||
}},
|
|
||||||
}
|
|
||||||
|
|
||||||
enc, aerr := actors.SerializeParams(params)
|
|
||||||
require.NoError(t, aerr)
|
|
||||||
|
|
||||||
msg := &types.Message{
|
|
||||||
To: evilMinerAddr,
|
|
||||||
Method: miner.Methods.SubmitWindowedPoSt,
|
|
||||||
Params: enc,
|
|
||||||
Value: types.NewInt(0),
|
|
||||||
From: minerInfo.Owner,
|
|
||||||
}
|
|
||||||
sm, err := client.MpoolPushMessage(ctx, msg, nil)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
fmt.Println("waiting for evil proof")
|
|
||||||
rec, err := client.StateWaitMsg(ctx, sm.Cid(), build.MessageConfidence)
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Zero(t, rec.Receipt.ExitCode, "evil proof not accepted: %s", rec.Receipt.ExitCode.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait until after the proving period.
|
// Wait until after the proving period.
|
||||||
for {
|
for {
|
||||||
@ -798,7 +760,7 @@ func TestWindowPostDispute(t *testing.T, b APIBuilder, blocktime time.Duration)
|
|||||||
Method: miner.Methods.DisputeWindowedPoSt,
|
Method: miner.Methods.DisputeWindowedPoSt,
|
||||||
Params: enc,
|
Params: enc,
|
||||||
Value: types.NewInt(0),
|
Value: types.NewInt(0),
|
||||||
From: minerInfo.Owner, // TODO: new miner...
|
From: defaultFrom, // TODO: new miner...
|
||||||
}
|
}
|
||||||
sm, err := client.MpoolPushMessage(ctx, msg, nil)
|
sm, err := client.MpoolPushMessage(ctx, msg, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -807,6 +769,7 @@ func TestWindowPostDispute(t *testing.T, b APIBuilder, blocktime time.Duration)
|
|||||||
rec, err := client.StateWaitMsg(ctx, sm.Cid(), build.MessageConfidence)
|
rec, err := client.StateWaitMsg(ctx, sm.Cid(), build.MessageConfidence)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Zero(t, rec.Receipt.ExitCode, "dispute not accepted: %s", rec.Receipt.ExitCode.Error())
|
require.Zero(t, rec.Receipt.ExitCode, "dispute not accepted: %s", rec.Receipt.ExitCode.Error())
|
||||||
|
fmt.Println("GASS!!!: ", rec.Receipt.GasUsed)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Objection SUSTAINED!
|
// Objection SUSTAINED!
|
||||||
@ -821,6 +784,9 @@ func TestWindowPostDispute(t *testing.T, b APIBuilder, blocktime time.Duration)
|
|||||||
// First, recover the sector.
|
// First, recover the sector.
|
||||||
|
|
||||||
{
|
{
|
||||||
|
minerInfo, err := client.StateMinerInfo(ctx, evilMinerAddr, types.EmptyTSK)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
params := &miner.DeclareFaultsRecoveredParams{
|
params := &miner.DeclareFaultsRecoveredParams{
|
||||||
Recoveries: []miner.RecoveryDeclaration{{
|
Recoveries: []miner.RecoveryDeclaration{{
|
||||||
Deadline: evilSectorLoc.Deadline,
|
Deadline: evilSectorLoc.Deadline,
|
||||||
@ -836,7 +802,7 @@ func TestWindowPostDispute(t *testing.T, b APIBuilder, blocktime time.Duration)
|
|||||||
To: evilMinerAddr,
|
To: evilMinerAddr,
|
||||||
Method: miner.Methods.DeclareFaultsRecovered,
|
Method: miner.Methods.DeclareFaultsRecovered,
|
||||||
Params: enc,
|
Params: enc,
|
||||||
Value: types.NewInt(0),
|
Value: types.FromFil(30), // repay debt.
|
||||||
From: minerInfo.Owner, // TODO: new miner...
|
From: minerInfo.Owner, // TODO: new miner...
|
||||||
}
|
}
|
||||||
sm, err := client.MpoolPushMessage(ctx, msg, nil)
|
sm, err := client.MpoolPushMessage(ctx, msg, nil)
|
||||||
@ -857,23 +823,47 @@ func TestWindowPostDispute(t *testing.T, b APIBuilder, blocktime time.Duration)
|
|||||||
build.Clock.Sleep(blocktime)
|
build.Clock.Sleep(blocktime)
|
||||||
}
|
}
|
||||||
|
|
||||||
// And prove it.
|
// Now try to be evil again
|
||||||
{
|
err = submitBadProof(ctx, client, evilMinerAddr, di, evilSectorLoc.Deadline, evilSectorLoc.Partition)
|
||||||
fmt.Println("submitting good proof")
|
require.Error(t, err)
|
||||||
|
require.Contains(t, err.Error(), "message execution failed: exit 16, reason: window post failed: invalid PoSt")
|
||||||
|
|
||||||
|
// It didn't work because we're recovering.
|
||||||
|
}
|
||||||
|
|
||||||
|
func submitBadProof(
|
||||||
|
ctx context.Context,
|
||||||
|
client api.FullNode, maddr address.Address,
|
||||||
|
di *dline.Info, dlIdx, partIdx uint64,
|
||||||
|
) error {
|
||||||
head, err := client.ChainHead(ctx)
|
head, err := client.ChainHead(ctx)
|
||||||
require.NoError(t, err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
from, err := client.WalletDefaultAddress(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
minerInfo, err := client.StateMinerInfo(ctx, maddr, head.Key())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
commEpoch := di.Open
|
commEpoch := di.Open
|
||||||
commRand, err := client.ChainGetRandomnessFromTickets(
|
commRand, err := client.ChainGetRandomnessFromTickets(
|
||||||
ctx, head.Key(), crypto.DomainSeparationTag_PoStChainCommit,
|
ctx, head.Key(), crypto.DomainSeparationTag_PoStChainCommit,
|
||||||
commEpoch, nil,
|
commEpoch, nil,
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
params := &miner.SubmitWindowedPoStParams{
|
params := &miner.SubmitWindowedPoStParams{
|
||||||
ChainCommitEpoch: commEpoch,
|
ChainCommitEpoch: commEpoch,
|
||||||
ChainCommitRand: commRand,
|
ChainCommitRand: commRand,
|
||||||
Deadline: evilSectorLoc.Deadline,
|
Deadline: dlIdx,
|
||||||
Partitions: []miner.PoStPartition{{Index: evilSectorLoc.Partition}},
|
Partitions: []miner.PoStPartition{{Index: partIdx}},
|
||||||
Proofs: []proof3.PoStProof{{
|
Proofs: []proof3.PoStProof{{
|
||||||
PoStProof: minerInfo.WindowPoStProofType,
|
PoStProof: minerInfo.WindowPoStProofType,
|
||||||
ProofBytes: []byte("I'm soooo very evil."),
|
ProofBytes: []byte("I'm soooo very evil."),
|
||||||
@ -881,26 +871,28 @@ func TestWindowPostDispute(t *testing.T, b APIBuilder, blocktime time.Duration)
|
|||||||
}
|
}
|
||||||
|
|
||||||
enc, aerr := actors.SerializeParams(params)
|
enc, aerr := actors.SerializeParams(params)
|
||||||
require.NoError(t, aerr)
|
if aerr != nil {
|
||||||
|
return aerr
|
||||||
|
}
|
||||||
|
|
||||||
msg := &types.Message{
|
msg := &types.Message{
|
||||||
To: evilMinerAddr,
|
To: maddr,
|
||||||
Method: miner.Methods.SubmitWindowedPoSt,
|
Method: miner.Methods.SubmitWindowedPoSt,
|
||||||
Params: enc,
|
Params: enc,
|
||||||
Value: types.NewInt(0),
|
Value: types.NewInt(0),
|
||||||
From: minerInfo.Owner,
|
From: from,
|
||||||
}
|
}
|
||||||
sm, err := client.MpoolPushMessage(ctx, msg, nil)
|
sm, err := client.MpoolPushMessage(ctx, msg, nil)
|
||||||
require.NoError(t, err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Println("waiting for evil proof")
|
|
||||||
rec, err := client.StateWaitMsg(ctx, sm.Cid(), build.MessageConfidence)
|
rec, err := client.StateWaitMsg(ctx, sm.Cid(), build.MessageConfidence)
|
||||||
require.NoError(t, err)
|
if err != nil {
|
||||||
require.Zero(t, rec.Receipt.ExitCode, "evil proof not accepted: %s", rec.Receipt.ExitCode.Error())
|
return err
|
||||||
}
|
}
|
||||||
|
if rec.Receipt.ExitCode.IsError() {
|
||||||
// The power should be restored.
|
return rec.Receipt.ExitCode
|
||||||
p, err = client.StateMinerPower(ctx, evilMinerAddr, types.EmptyTSK)
|
}
|
||||||
require.NoError(t, err)
|
return nil
|
||||||
require.Equal(t, p.MinerPower.RawBytePower, types.NewInt(uint64(ssz)))
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user