Make EquivocationDelaySecs a build param

This commit is contained in:
Aayush 2023-08-11 10:36:17 -04:00
parent 668d615be6
commit 43d1d62fc6
8 changed files with 25 additions and 13 deletions

View File

@ -132,6 +132,8 @@ const BlockDelaySecs = uint64(4)
const PropagationDelaySecs = uint64(1) const PropagationDelaySecs = uint64(1)
var EquivocationDelaySecs = uint64(0)
// SlashablePowerDelay is the number of epochs after ElectionPeriodStart, after // SlashablePowerDelay is the number of epochs after ElectionPeriodStart, after
// which the miner is slashed // which the miner is slashed
// //

View File

@ -86,6 +86,8 @@ const BlockDelaySecs = uint64(builtin2.EpochDurationSeconds)
const PropagationDelaySecs = uint64(6) const PropagationDelaySecs = uint64(6)
var EquivocationDelaySecs = uint64(2)
// BootstrapPeerThreshold is the minimum number peers we need to track for a sync worker to start // BootstrapPeerThreshold is the minimum number peers we need to track for a sync worker to start
const BootstrapPeerThreshold = 2 const BootstrapPeerThreshold = 2

View File

@ -123,6 +123,8 @@ const BlockDelaySecs = uint64(builtin2.EpochDurationSeconds)
var PropagationDelaySecs = uint64(10) var PropagationDelaySecs = uint64(10)
var EquivocationDelaySecs = uint64(2)
// BootstrapPeerThreshold is the minimum number peers we need to track for a sync worker to start // BootstrapPeerThreshold is the minimum number peers we need to track for a sync worker to start
const BootstrapPeerThreshold = 4 const BootstrapPeerThreshold = 4

View File

@ -121,6 +121,8 @@ const BlockDelaySecs = uint64(builtin2.EpochDurationSeconds)
const PropagationDelaySecs = uint64(6) const PropagationDelaySecs = uint64(6)
var EquivocationDelaySecs = uint64(2)
// BootstrapPeerThreshold is the minimum number peers we need to track for a sync worker to start // BootstrapPeerThreshold is the minimum number peers we need to track for a sync worker to start
const BootstrapPeerThreshold = 2 const BootstrapPeerThreshold = 2

View File

@ -105,6 +105,7 @@ var SupportedProofTypes = []abi.RegisteredSealProof{
var ConsensusMinerMinPower = abi.NewStoragePower(10 << 40) var ConsensusMinerMinPower = abi.NewStoragePower(10 << 40)
var PreCommitChallengeDelay = abi.ChainEpoch(150) var PreCommitChallengeDelay = abi.ChainEpoch(150)
var PropagationDelaySecs = uint64(10) var PropagationDelaySecs = uint64(10)
var EquivocationDelaySecs = uint64(2) var EquivocationDelaySecs = uint64(2)
func init() { func init() {

View File

@ -9,7 +9,6 @@ package build
import ( import (
"math/big" "math/big"
"time"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
@ -34,6 +33,7 @@ var (
MinimumBaseFee = int64(100) MinimumBaseFee = int64(100)
BlockDelaySecs = uint64(builtin2.EpochDurationSeconds) BlockDelaySecs = uint64(builtin2.EpochDurationSeconds)
PropagationDelaySecs = uint64(6) PropagationDelaySecs = uint64(6)
EquivocationDelaySecs = uint64(2)
SupportedProofTypes = []abi.RegisteredSealProof{ SupportedProofTypes = []abi.RegisteredSealProof{
abi.RegisteredSealProof_StackedDrg32GiBV1, abi.RegisteredSealProof_StackedDrg32GiBV1,
abi.RegisteredSealProof_StackedDrg64GiBV1, abi.RegisteredSealProof_StackedDrg64GiBV1,
@ -139,7 +139,3 @@ const BootstrapPeerThreshold = 1
// ChainId defines the chain ID used in the Ethereum JSON-RPC endpoint. // ChainId defines the chain ID used in the Ethereum JSON-RPC endpoint.
// As per https://github.com/ethereum-lists/chains // As per https://github.com/ethereum-lists/chains
const Eip155ChainId = 31415926 const Eip155ChainId = 31415926
// Reducing the delivery delay for equivocation of
// consistent broadcast to just half a second.
var CBDeliveryDelay = 500 * time.Millisecond

View File

@ -169,6 +169,8 @@ func NewEnsemble(t *testing.T, opts ...EnsembleOpt) *Ensemble {
require.NoError(t, build.UseNetworkBundle("testing")) require.NoError(t, build.UseNetworkBundle("testing"))
} }
build.EquivocationDelaySecs = 0
return n return n
} }

View File

@ -568,19 +568,16 @@ func (m *Miner) mineOne(ctx context.Context, base *MiningBase) (minedBlock *type
// To safeguard against this, we make sure it's been EquivocationDelaySecs since our base was calculated, // To safeguard against this, we make sure it's been EquivocationDelaySecs since our base was calculated,
// then re-calculate it. // then re-calculate it.
// If the daemon detected equivocated blocks, those blocks will no longer be in the new base. // If the daemon detected equivocated blocks, those blocks will no longer be in the new base.
// TODO: make param m.niceSleep(time.Until(base.ComputeTime.Add(time.Duration(build.EquivocationDelaySecs) * time.Second)))
m.niceSleep(time.Until(base.ComputeTime.Add(2 * time.Second)))
newBase, err := m.GetBestMiningCandidate(ctx) newBase, err := m.GetBestMiningCandidate(ctx)
if err != nil { if err != nil {
err = xerrors.Errorf("failed to refresh best mining candidate: %w", err) err = xerrors.Errorf("failed to refresh best mining candidate: %w", err)
return nil, err return nil, err
} }
// If the MinTicket is still the same, we take the _intersection_ of our old base and new base, // If the base has changed, we take the _intersection_ of our old base and new base,
// thus ejecting blocks from any equivocating miners, without taking any new blocks. // thus ejecting blocks from any equivocating miners, without taking any new blocks.
// If the MinTicket is not the same, then the work we've done so far is no longer valid. if !newBase.TipSet.Equals(base.TipSet) {
// Instead of choosing to miss a block, we submit our best-effort block anyway.
if !newBase.TipSet.Equals(base.TipSet) && newBase.TipSet.MinTicket().Equals(base.TipSet.MinTicket()) {
newBaseMap := map[cid.Cid]struct{}{} newBaseMap := map[cid.Cid]struct{}{}
for _, newBaseBlk := range newBase.TipSet.Cids() { for _, newBaseBlk := range newBase.TipSet.Cids() {
newBaseMap[newBaseBlk] = struct{}{} newBaseMap[newBaseBlk] = struct{}{}
@ -600,14 +597,22 @@ func (m *Miner) mineOne(ctx context.Context, base *MiningBase) (minedBlock *type
return nil, err return nil, err
} }
base.TipSet = refreshedBase if !base.TipSet.MinTicket().Equals(refreshedBase.MinTicket()) {
ticket, err = m.computeTicket(ctx, &rbase, round, refreshedBase.MinTicket(), mbi)
if err != nil {
err = xerrors.Errorf("failed to refresh ticket: %w", err)
return nil, err
}
}
// refresh messages, as the selected messages may no longer be valid // refresh messages, as the selected messages may no longer be valid
msgs, err = m.api.MpoolSelect(ctx, base.TipSet.Key(), ticket.Quality()) msgs, err = m.api.MpoolSelect(ctx, refreshedBase.Key(), ticket.Quality())
if err != nil { if err != nil {
err = xerrors.Errorf("failed to re-select messages for block: %w", err) err = xerrors.Errorf("failed to re-select messages for block: %w", err)
return nil, err return nil, err
} }
base.TipSet = refreshedBase
} }
} }