Skip to content

Commit

Permalink
Add support for message perturbations to SMR
Browse files Browse the repository at this point in the history
The SMR system can now be configured (using PerturbMessages)
to artificially introduce random delays and loss to all sent messages.

Signed-off-by: Matej Pavlovic <[email protected]>
  • Loading branch information
matejpavlovic committed Nov 15, 2022
1 parent edc9bfd commit 2fa6d0e
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions pkg/systems/smr/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@ import (
"github.com/libp2p/go-libp2p-core/host"
"github.com/pkg/errors"

"github.com/filecoin-project/mir/pkg/net"

"github.com/filecoin-project/mir/pkg/checkpoint"

"github.com/filecoin-project/mir/pkg/availability/batchdb/fakebatchdb"
"github.com/filecoin-project/mir/pkg/availability/multisigcollector"
"github.com/filecoin-project/mir/pkg/batchfetcher"
"github.com/filecoin-project/mir/pkg/checkpoint"
mircrypto "github.com/filecoin-project/mir/pkg/crypto"
"github.com/filecoin-project/mir/pkg/eventmangler"
"github.com/filecoin-project/mir/pkg/iss"
"github.com/filecoin-project/mir/pkg/logging"
"github.com/filecoin-project/mir/pkg/mempool/simplemempool"
"github.com/filecoin-project/mir/pkg/modules"
"github.com/filecoin-project/mir/pkg/net"
libp2pnet "github.com/filecoin-project/mir/pkg/net/libp2p"
t "github.com/filecoin-project/mir/pkg/types"
)
Expand Down Expand Up @@ -50,6 +49,28 @@ func (sys *System) WithModule(moduleID t.ModuleID, module modules.Module) *Syste
return sys
}

// PerturbMessages configures the SMR system to randomly drop and delay some of the messages sent over the network.
// Useful for debugging and stress-testing.
// The params argument defines parameters of the perturbation, such as how many messages should be dropped
// and how the remaining messages should be delayed.
func (sys *System) PerturbMessages(params *eventmangler.ModuleParams) error {

// Create event mangler perturbing (dropping and delaying) events.
messageMangler, err := eventmangler.NewModule(
&eventmangler.ModuleConfig{Self: "net", Dest: "truenet", Timer: "timer"},
params,
)
if err != nil {
return err
}

// Intercept all events (in this case SendMessage events) directed to the "net" module by the mangler
// And change the actual transport module ID to "truenet", where the mangler forwards the surviving messages.
sys.modules[iss.DefaultModuleConfig().Net] = messageMangler
sys.modules["truenet"] = sys.transport
return nil
}

// Start starts the operation of the modules of the SMR system.
// It starts the network transport and connects to the initial members of the system.
func (sys *System) Start() error {
Expand Down

0 comments on commit 2fa6d0e

Please sign in to comment.