Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions sim/adversary/absent.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ func NewAbsent(id gpbft.ActorID, host gpbft.Host) *Absent {
}
}

func NewAbsentGenerator(power *gpbft.StoragePower) Generator {
return func(id gpbft.ActorID, host Host) *Adversary {
return &Adversary{
Receiver: NewAbsent(id, host),
Power: power,
}
}
}

func (a *Absent) ID() gpbft.ActorID {
return a.id
}
Expand Down
7 changes: 7 additions & 0 deletions sim/adversary/api.go → sim/adversary/adversary.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@ type Host interface {
// before messages are actually received.
BroadcastSynchronous(sender gpbft.ActorID, msg gpbft.GMessage)
}

type Generator func(gpbft.ActorID, Host) *Adversary

type Adversary struct {
Receiver
Power *gpbft.StoragePower
}
46 changes: 26 additions & 20 deletions sim/adversary/decide.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,20 @@ func NewImmediateDecide(id gpbft.ActorID, host Host, value gpbft.ECChain) *Immed
}
}

func NewImmediateDecideGenerator(value gpbft.ECChain, power *gpbft.StoragePower) Generator {
return func(id gpbft.ActorID, host Host) *Adversary {
return &Adversary{
Receiver: NewImmediateDecide(id, host, value),
Power: power,
}
}
}

func (i *ImmediateDecide) ID() gpbft.ActorID {
return i.id
}

func (i *ImmediateDecide) Start() error {
return nil
}

func (i *ImmediateDecide) ReceiveECChain(gpbft.ECChain) error {
return nil
}

func (i *ImmediateDecide) ValidateMessage(_ *gpbft.GMessage) (bool, error) {
return true, nil
}

func (i *ImmediateDecide) ReceiveMessage(_ *gpbft.GMessage, _ bool) (bool, error) {
return true, nil
}

func (i *ImmediateDecide) ReceiveAlarm() error {
return nil
}

func (i *ImmediateDecide) Begin() {
_, powertable, _ := i.host.GetCanonicalChain()
// Immediately send a DECIDE message
payload := gpbft.Payload{
Expand Down Expand Up @@ -82,6 +71,23 @@ func (i *ImmediateDecide) Begin() {
}

i.broadcast(payload, &justification, powertable)
return nil
}

func (i *ImmediateDecide) ReceiveECChain(gpbft.ECChain) error {
return nil
}

func (i *ImmediateDecide) ValidateMessage(_ *gpbft.GMessage) (bool, error) {
return true, nil
}

func (i *ImmediateDecide) ReceiveMessage(_ *gpbft.GMessage, _ bool) (bool, error) {
return true, nil
}

func (i *ImmediateDecide) ReceiveAlarm() error {
return nil
}

func (i *ImmediateDecide) AllowMessage(_ gpbft.ActorID, _ gpbft.ActorID, _ gpbft.GMessage) bool {
Expand Down
9 changes: 9 additions & 0 deletions sim/adversary/repeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ func NewRepeat(id gpbft.ActorID, host gpbft.Host, sampler RepetitionSampler) *Re
}
}

func NewRepeatGenerator(power *gpbft.StoragePower, sampler RepetitionSampler) Generator {
return func(id gpbft.ActorID, host Host) *Adversary {
return &Adversary{
Receiver: NewRepeat(id, host, sampler),
Power: power,
}
}
}

func (r *Repeat) ReceiveMessage(msg *gpbft.GMessage, _ bool) (bool, error) {
echoCount := r.repetitionSampler(msg)
if echoCount <= 0 {
Expand Down
50 changes: 32 additions & 18 deletions sim/adversary/withhold.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package adversary

import (
"errors"
"sort"

"github.com/filecoin-project/go-bitfield"
Expand Down Expand Up @@ -28,6 +29,17 @@ func NewWitholdCommit(id gpbft.ActorID, host Host) *WithholdCommit {
}
}

func NewWitholdCommitGenerator(power *gpbft.StoragePower, victims []gpbft.ActorID, victimValue gpbft.ECChain) Generator {
return func(id gpbft.ActorID, host Host) *Adversary {
wc := NewWitholdCommit(id, host)
wc.SetVictim(victims, victimValue)
return &Adversary{
Receiver: wc,
Power: power,
}
}
}

func (w *WithholdCommit) SetVictim(victims []gpbft.ActorID, victimValue gpbft.ECChain) {
w.victims = victims
w.victimValue = victimValue
Expand All @@ -38,26 +50,11 @@ func (w *WithholdCommit) ID() gpbft.ActorID {
}

func (w *WithholdCommit) Start() error {
return nil
}

func (w *WithholdCommit) ReceiveECChain(gpbft.ECChain) error {
return nil
}

func (a *WithholdCommit) ValidateMessage(_ *gpbft.GMessage) (bool, error) {
return true, nil
}

func (a *WithholdCommit) ReceiveMessage(_ *gpbft.GMessage, _ bool) (bool, error) {
return true, nil
}

func (w *WithholdCommit) ReceiveAlarm() error {
return nil
}
if len(w.victims) == 0 {
return errors.New("victims must be set")
}

func (w *WithholdCommit) Begin() {
_, powertable, _ := w.host.GetCanonicalChain()
broadcast := w.broadcastHelper(w.id, powertable)
// All victims need to see QUALITY and PREPARE in order to send their COMMIT,
Expand Down Expand Up @@ -114,6 +111,23 @@ func (w *WithholdCommit) Begin() {
}

broadcast(commitPayload, &justification)
return nil
}

func (w *WithholdCommit) ReceiveECChain(gpbft.ECChain) error {
return nil
}

func (a *WithholdCommit) ValidateMessage(_ *gpbft.GMessage) (bool, error) {
return true, nil
}

func (a *WithholdCommit) ReceiveMessage(_ *gpbft.GMessage, _ bool) (bool, error) {
return true, nil
}

func (w *WithholdCommit) ReceiveAlarm() error {
return nil
}

func (w *WithholdCommit) AllowMessage(_ gpbft.ActorID, to gpbft.ActorID, msg gpbft.GMessage) bool {
Expand Down
42 changes: 33 additions & 9 deletions sim/cmd/f3sim/f3sim.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (

"github.com/filecoin-project/go-f3/gpbft"
"github.com/filecoin-project/go-f3/sim"
"github.com/filecoin-project/go-f3/sim/latency"
"github.com/filecoin-project/go-f3/sim/signing"
)

func main() {
Expand All @@ -28,24 +30,46 @@ func main() {
seed := *latencySeed + int64(i)
fmt.Printf("Iteration %d: seed=%d, mean=%f\n", i, seed, *latencyMean)

simConfig := sim.Config{
HonestCount: *participantCount,
LatencySeed: *latencySeed,
LatencyMean: time.Duration(*latencyMean * float64(time.Second)),
ECEpochDuration: 30 * time.Second,
ECStabilisationDelay: 0,
latencyModel, err := latency.NewLogNormal(*latencySeed, time.Duration(*latencyMean*float64(time.Second)))
if err != nil {
log.Panicf("failed to instantiate log normal latency model: %c\n", err)
}

tsg := sim.NewTipSetGenerator(uint64(seed))
baseChain, err := gpbft.NewChain(tsg.Sample())
if err != nil {
log.Fatalf("failed to generate base chain: %v\n", err)
}
graniteConfig := gpbft.GraniteConfig{

graniteConfig := &gpbft.GraniteConfig{
Delta: time.Duration(*graniteDelta * float64(time.Second)),
DeltaBackOffExponent: *deltaBackOffExponent,
}
sm, err := sim.NewSimulation(simConfig, graniteConfig, *traceLevel)
options := []sim.Option{
sim.WithHonestParticipantCount(*participantCount),
sim.WithLatencyModel(latencyModel),
sim.WithECEpochDuration(30 * time.Second),
sim.WithECStabilisationDelay(0),
sim.WithTipSetGenerator(tsg),
sim.WithBaseChain(&baseChain),
sim.WithTraceLevel(*traceLevel),
sim.WithGraniteConfig(graniteConfig),
}

if os.Getenv("F3_TEST_USE_BLS") == "1" {
options = append(options, sim.WithSigningBackend(signing.NewBLSBackend()))
}

sm, err := sim.NewSimulation(options...)
if err != nil {
return
}
if err != nil {
log.Panicf("failed to instantiate simulation: %v\n", err)
}

// Same chain for everyone.
candidate := sm.Base(0).Extend(sm.TipGen.Sample())
candidate := baseChain.Extend(tsg.Sample())
sm.SetChains(sim.ChainCount{Count: *participantCount, Chain: candidate})

if err := sm.Run(1, *maxRounds); err != nil {
Expand Down
27 changes: 0 additions & 27 deletions sim/config.go

This file was deleted.

15 changes: 8 additions & 7 deletions sim/decision_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import (

// Receives and validates finality decisions
type DecisionLog struct {
Network gpbft.Network
Verifier gpbft.Verifier
netName gpbft.NetworkName
verifier gpbft.Verifier

// Base tipset for each instance.
Bases []gpbft.TipSet
// Powertable for each instance.
Expand All @@ -20,10 +21,10 @@ type DecisionLog struct {
err error
}

func NewDecisionLog(ntwk gpbft.Network, verifier gpbft.Verifier) *DecisionLog {
func newDecisionLog(opts *options) *DecisionLog {
return &DecisionLog{
Network: ntwk,
Verifier: verifier,
netName: opts.networkName,
verifier: opts.signingBacked,
}
}

Expand Down Expand Up @@ -155,8 +156,8 @@ func (dl *DecisionLog) verifyDecision(decision *gpbft.Justification) error {
return fmt.Errorf("decision lacks strong quorum: %v", decision)
}
// Verify aggregate signature
payload := decision.Vote.MarshalForSigning(dl.Network.NetworkName())
if err := dl.Verifier.VerifyAggregate(payload, decision.Signature, signers); err != nil {
payload := decision.Vote.MarshalForSigning(dl.netName)
if err := dl.verifier.VerifyAggregate(payload, decision.Signature, signers); err != nil {
return xerrors.Errorf("invalid aggregate signature: %v: %w", decision, err)
}
return nil
Expand Down
6 changes: 3 additions & 3 deletions sim/ec.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ type ECInstance struct {
Beacon []byte
}

func NewEC(base gpbft.ECChain, beacon []byte) *EC {
func newEC(opts *options) *EC {
return &EC{
BaseTimestamp: time.Time{},
Instances: []*ECInstance{
{
Base: base,
Base: *opts.baseChain,
Chains: make(map[gpbft.ActorID]gpbft.ECChain),
PowerTable: gpbft.NewPowerTable(),
Beacon: beacon,
Beacon: opts.beacon,
},
},
}
Expand Down
Loading