Skip to content

Commit

Permalink
Merge branch 'consensus-shipyard:main' into reactFrontend_closeButton
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaj00 authored Feb 15, 2024
2 parents 0933aa7 + 92a1b70 commit 5a59d00
Show file tree
Hide file tree
Showing 318 changed files with 7,070 additions and 9,511 deletions.
3 changes: 2 additions & 1 deletion cmd/bench/cmd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ import (
"github.com/spf13/cobra"
rateLimiter "golang.org/x/time/rate"

t "github.com/filecoin-project/mir/stdtypes"

"github.com/filecoin-project/mir/pkg/dummyclient"
"github.com/filecoin-project/mir/pkg/logging"
"github.com/filecoin-project/mir/pkg/membership"
tt "github.com/filecoin-project/mir/pkg/trantor/types"
t "github.com/filecoin-project/mir/pkg/types"
)

const (
Expand Down
34 changes: 10 additions & 24 deletions cmd/bench/cmd/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"fmt"
"net"
"os"
"strconv"
"time"

es "github.com/go-errors/errors"
Expand All @@ -25,14 +24,13 @@ import (
"github.com/filecoin-project/mir/pkg/deploytest"
"github.com/filecoin-project/mir/pkg/logging"
"github.com/filecoin-project/mir/pkg/membership"
libp2p2 "github.com/filecoin-project/mir/pkg/net/libp2p"
"github.com/filecoin-project/mir/pkg/net/grpc"
"github.com/filecoin-project/mir/pkg/rendezvous"
"github.com/filecoin-project/mir/pkg/trantor"
"github.com/filecoin-project/mir/pkg/trantor/appmodule"
tt "github.com/filecoin-project/mir/pkg/trantor/types"
t "github.com/filecoin-project/mir/pkg/types"
"github.com/filecoin-project/mir/pkg/util/libp2p"
"github.com/filecoin-project/mir/pkg/util/maputil"
"github.com/filecoin-project/mir/stdtypes"
)

const (
Expand Down Expand Up @@ -96,18 +94,12 @@ func runNode() error {
return es.Errorf("could not load parameters from file '%s': %w", configFileName, err)
}

// Parse own ID.
ownNumericID, err := strconv.Atoi(id)
if err != nil {
return es.Errorf("unable to convert node ID: %w", err)
}

// Check if own id is in the membership
initialMembership := params.Trantor.Iss.InitialMembership
if _, ok := initialMembership.Nodes[t.NodeID(id)]; !ok {
if _, ok := initialMembership.Nodes[stdtypes.NodeID(id)]; !ok {
return es.Errorf("own ID (%v) not found in membership (%v)", id, maputil.GetKeys(initialMembership.Nodes))
}
ownID := t.NodeID(id)
ownID := stdtypes.NodeID(id)

// Assemble listening address.
// In this benchmark code, we always listen on the address 0.0.0.0.
Expand All @@ -121,20 +113,14 @@ func runNode() error {
return es.Errorf("could not create listen address: %w", err)
}

// Create libp2p host
h, err := libp2p.NewDummyHostWithPrivKey(
t.NodeAddress(libp2p.NewDummyMultiaddr(ownNumericID, listenAddr)),
libp2p.NewDummyHostKey(ownNumericID),
)
if err != nil {
return es.Errorf("failed to create libp2p host: %w", err)
}

// Initialize tracking of networking statistics.
netStats := stats.NewNetStats(time.Second)

// Initialize the libp2p transport subsystem.
transport := libp2p2.NewTransport(params.Trantor.Net, ownID, h, logger, netStats)
// Initialize the grpc transport subsystem.
transport, err := grpc.NewTransport(params.Trantor.Net, ownID, listenAddr.String(), logger, netStats)
if err != nil {
return es.Errorf("failed to create grpc transport: %w", err)
}

// Instantiate the crypto module.
localCryptoSystem, err := deploytest.NewLocalCryptoSystem("pseudo", membership.GetIDs(initialMembership), logger)
Expand Down Expand Up @@ -187,7 +173,7 @@ func runNode() error {
// Instantiate the Mir Node.
nodeConfig := mir.DefaultNodeConfig().WithLogger(logger)
nodeConfig.Stats.Period = time.Second
node, err := mir.NewNode(t.NodeID(id), nodeConfig, trantorInstance.Modules(), nil)
node, err := mir.NewNode(stdtypes.NodeID(id), nodeConfig, trantorInstance.Modules(), nil)
if err != nil {
return es.Errorf("could not create node: %w", err)
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/bench/localtxgenerator/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (
"sync"
"sync/atomic"

es "github.com/go-errors/errors"

"github.com/filecoin-project/mir/cmd/bench/stats"
"github.com/filecoin-project/mir/pkg/logging"
"github.com/filecoin-project/mir/pkg/pb/eventpb"
mempoolpbevents "github.com/filecoin-project/mir/pkg/pb/mempoolpb/events"
trantorpbtypes "github.com/filecoin-project/mir/pkg/pb/trantorpb/types"
tt "github.com/filecoin-project/mir/pkg/trantor/types"
"github.com/filecoin-project/mir/stdtypes"

es "github.com/go-errors/errors"
)

type client struct {
Expand All @@ -24,14 +24,14 @@ type client struct {
randSource *rand.Rand
nextTXNo tt.TxNo
statsTrackers []stats.Tracker
txOutChan chan *eventpb.Event
txOutChan chan stdtypes.Event
txDeliverChan chan *trantorpbtypes.Transaction
stopChan chan struct{}
wg sync.WaitGroup
logger logging.Logger
}

func newClient(id tt.ClientID, moduleConfig ModuleConfig, params ModuleParams, txOutChan chan *eventpb.Event, logger logging.Logger) *client {
func newClient(id tt.ClientID, moduleConfig ModuleConfig, params ModuleParams, txOutChan chan stdtypes.Event, logger logging.Logger) *client {
seed := make([]byte, 8)
copy(seed, id.Bytes())
return &client{
Expand Down
27 changes: 14 additions & 13 deletions cmd/bench/localtxgenerator/localtxgenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ import (
"sync/atomic"
"time"

"github.com/filecoin-project/mir/stdevents"
"github.com/filecoin-project/mir/stdtypes"

"github.com/filecoin-project/mir/cmd/bench/stats"
"github.com/filecoin-project/mir/pkg/checkpoint"
"github.com/filecoin-project/mir/pkg/events"
"github.com/filecoin-project/mir/pkg/logging"
"github.com/filecoin-project/mir/pkg/pb/eventpb"
trantorpbtypes "github.com/filecoin-project/mir/pkg/pb/trantorpb/types"
tt "github.com/filecoin-project/mir/pkg/trantor/types"
t "github.com/filecoin-project/mir/pkg/types"
)

type ModuleConfig struct {
Mempool t.ModuleID
Mempool stdtypes.ModuleID
}

func DefaultModuleConfig() ModuleConfig {
Expand All @@ -43,16 +43,16 @@ type LocalTXGen struct {
modules ModuleConfig
params ModuleParams
statsTrackers []stats.Tracker
txChan chan *eventpb.Event
txChan chan stdtypes.Event
clients map[tt.ClientID]*client

eventsOut chan *events.EventList
eventsOut chan *stdtypes.EventList
wg sync.WaitGroup
stopChan chan struct{}
}

func New(moduleConfig ModuleConfig, params ModuleParams) *LocalTXGen {
txChan := make(chan *eventpb.Event, params.NumClients)
txChan := make(chan stdtypes.Event, params.NumClients)
logger := logging.ConsoleInfoLogger

clients := make(map[tt.ClientID]*client, params.NumClients)
Expand All @@ -66,7 +66,7 @@ func New(moduleConfig ModuleConfig, params ModuleParams) *LocalTXGen {
params: params,
txChan: txChan,
clients: clients,
eventsOut: make(chan *events.EventList),
eventsOut: make(chan *stdtypes.EventList),
stopChan: make(chan struct{}),
}
}
Expand All @@ -93,7 +93,7 @@ func (gen *LocalTXGen) Start() {
go func() {
defer gen.wg.Done()

txEventList := events.EmptyList()
txEventList := stdtypes.EmptyList()

for {
// Give priority to collecting submitted transactions.
Expand All @@ -107,7 +107,7 @@ func (gen *LocalTXGen) Start() {
case txEvent := <-gen.txChan:
txEventList.PushBack(txEvent)
case gen.eventsOut <- txEventList:
txEventList = events.EmptyList()
txEventList = stdtypes.EmptyList()
case <-gen.stopChan:
return
}
Expand Down Expand Up @@ -154,17 +154,18 @@ func (gen *LocalTXGen) Stop() {
func (gen *LocalTXGen) ImplementsModule() {}

// ApplyEvents returns an error on any event it receives, except fot the Init event, which it silently ignores.
func (gen *LocalTXGen) ApplyEvents(_ context.Context, evts *events.EventList) error {
func (gen *LocalTXGen) ApplyEvents(_ context.Context, evts *stdtypes.EventList) error {
for _, evt := range evts.Slice() {
if _, ok := evt.Type.(*eventpb.Event_Init); !ok {
// Complain about anything else than an Init event.
if _, ok := evt.(*stdevents.Init); !ok {
return fmt.Errorf("local request generator cannot apply events other than Init")
}
}
return nil
}

// EventsOut returns the channel to which LocalTXGen writes all output events (in this case just NewRequests events).
func (gen *LocalTXGen) EventsOut() <-chan *events.EventList {
func (gen *LocalTXGen) EventsOut() <-chan *stdtypes.EventList {
return gen.eventsOut
}

Expand Down
19 changes: 12 additions & 7 deletions cmd/bench/stats/stat-interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
package stats

import (
"github.com/filecoin-project/mir/pkg/events"
bfpb "github.com/filecoin-project/mir/pkg/pb/batchfetcherpb"
"github.com/filecoin-project/mir/pkg/pb/eventpb"
"github.com/filecoin-project/mir/pkg/pb/mempoolpb"
trantorpbtypes "github.com/filecoin-project/mir/pkg/pb/trantorpb/types"
t "github.com/filecoin-project/mir/pkg/types"
"github.com/filecoin-project/mir/stdtypes"
)

type StatInterceptor struct {
Expand All @@ -19,14 +18,14 @@ type StatInterceptor struct {
// ID of the module that is consuming the transactions.
// Statistics will only be performed on transactions destined to this module
// and the rest of the events will be ignored by the StatInterceptor.
txConsumerModule t.ModuleID
txConsumerModule stdtypes.ModuleID
}

func NewStatInterceptor(s *LiveStats, txConsumer t.ModuleID) *StatInterceptor {
func NewStatInterceptor(s *LiveStats, txConsumer stdtypes.ModuleID) *StatInterceptor {
return &StatInterceptor{s, txConsumer}
}

func (i *StatInterceptor) Intercept(events *events.EventList) error {
func (i *StatInterceptor) Intercept(events *stdtypes.EventList) error {

// Avoid nil dereference if Intercept is called on a nil *Recorder and simply do nothing.
// This can happen if a pointer type to *Recorder is assigned to a variable with the interface type Interceptor.
Expand All @@ -39,7 +38,13 @@ func (i *StatInterceptor) Intercept(events *events.EventList) error {
it := events.Iterator()
for evt := it.Next(); evt != nil; evt = it.Next() {

switch e := evt.Type.(type) {
// Skip events of unknown types.
pbevt, ok := evt.(*eventpb.Event)
if !ok {
continue
}

switch e := pbevt.Type.(type) {
case *eventpb.Event_Mempool:
switch e := e.Mempool.Type.(type) {
case *mempoolpb.Event_NewTransactions:
Expand All @@ -50,7 +55,7 @@ func (i *StatInterceptor) Intercept(events *events.EventList) error {
case *eventpb.Event_BatchFetcher:

// Skip events destined to other modules than the one consuming the transactions.
if t.ModuleID(evt.DestModule) != i.txConsumerModule {
if evt.Dest() != i.txConsumerModule {
continue
}

Expand Down
8 changes: 5 additions & 3 deletions cmd/mircat/customtransform.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package main

import "github.com/filecoin-project/mir/pkg/pb/eventpb"
import (
"github.com/filecoin-project/mir/stdtypes"
)

// This function is applied to every event loaded from the event log
// and its return value is used instead of the original event.
// If customEventFilter returns nil, the event is ignored (this can be used for additional event filtering).
// It is meant for ad-hoc editing while debugging, to be able to select events in a fine-grained way.
func customTransform(e *eventpb.Event) *eventpb.Event {
func customTransform(e stdtypes.Event) stdtypes.Event {

//moduleID := ""
//if e.DestModule == moduleID {
//if e.Dest() == moduleID {
// return e
//}
//return nil
Expand Down
Loading

0 comments on commit 5a59d00

Please sign in to comment.