smr

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2022 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenesisCheckpoint

func GenesisCheckpoint(initialAppState []byte, params Params) *checkpoint.StableCheckpoint

GenesisCheckpoint returns an initial stable checkpoint used for bootstrapping. It is a special checkpoint for epoch 0, corresponding to the state of the application (the serialization of which is passed as the initialAppState parameter) before applying any transactions. The associated certificate is empty (and should still be considered valid, as a special case).

Types

type AppLogic

type AppLogic interface {

	// ApplyTXs applies a batch of transactions to the state machine.
	ApplyTXs(txs []*requestpb.Request) error

	// NewEpoch is called by the SMR system when a new epoch is started.
	// It returns the membership of a new epoch.
	// Note that, due to pipelining, the membership NewEpoch returns is not necessarily used immediately
	// in the epoch that is just starting.
	// It might define the membership of a future epoch.
	NewEpoch(nr t.EpochNr) (map[t.NodeID]t.NodeAddress, error)

	// Snapshot returns a snapshot of the application state.
	Snapshot() ([]byte, error)

	// RestoreState restores the application state from stable checkpoint.
	RestoreState(checkpoint *checkpoint.StableCheckpoint) error

	// Checkpoint is called by the SMR system when it produces a checkpoint.
	// A checkpoint contains the state of the application at a particular point in time
	// from which the system can recover, including the configuration of the system at that point in time
	// and a certificate of validity of the checkpoint.
	Checkpoint(checkpoint *checkpoint.StableCheckpoint) error
}

AppLogic represents the application logic of an SMR system. It holds the state of the replicated state machine and defines the semantics of transactions applied to it. It also defines the membership of the system through the return value of NewEpoch.

func AppLogicFromStatic

func AppLogicFromStatic(staticAppLogic StaticAppLogic, membership map[t.NodeID]t.NodeAddress) AppLogic

AppLogicFromStatic augments the static application logic with a default implementation of the reconfiguration logic that simply always uses the same membership.

type AppModule

type AppModule struct {
	// contains filtered or unexported fields
}

AppModule is the module within the SMR system that handles the application logic.

func NewAppModule

func NewAppModule(appLogic AppLogic, transport net.Transport, protocolModule t.ModuleID) *AppModule

NewAppModule creates a new AppModule.

func (*AppModule) ApplyEvent

func (m *AppModule) ApplyEvent(event *eventpb.Event) (*events.EventList, error)

ApplyEvent applies a single event to the AppModule.

func (*AppModule) ApplyEvents

func (m *AppModule) ApplyEvents(eventsIn *events.EventList) (*events.EventList, error)

ApplyEvents applies a list of events to the AppModule.

func (*AppModule) ImplementsModule

func (m *AppModule) ImplementsModule()

The ImplementsModule method only serves the purpose of indicating that this is a Module and must not be called.

type Params

type Params struct {
	Mempool *simplemempool.ModuleParams
	Iss     *iss.ModuleParams
	Net     libp2p.Params
}

func DefaultParams

func DefaultParams(initialMembership map[t.NodeID]t.NodeAddress) Params

func (*Params) AdjustSpeed

func (p *Params) AdjustSpeed(maxProposeDelay time.Duration) *Params

type StaticAppLogic

type StaticAppLogic interface {

	// ApplyTXs applies a batch of transactions to the state machine.
	ApplyTXs(txs []*requestpb.Request) error

	// Snapshot returns a snapshot of the application state.
	Snapshot() ([]byte, error)

	// RestoreState restores the application state from a snapshot.
	RestoreState(checkpoint *checkpoint.StableCheckpoint) error

	// Checkpoint is called by the SMR system when it produces a checkpoint.
	// A checkpoint contains the state of the application at a particular point in time
	// from which the system can recover, including the configuration of the system at that point in time
	// and a certificate of validity of the checkpoint.
	Checkpoint(checkpoint *checkpoint.StableCheckpoint) error
}

StaticAppLogic represents the logic of an application that is not reconfigurable. It is simpler than AppLogic, as it does not need to define the membership of the system.

type System

type System struct {
	// contains filtered or unexported fields
}

System represents a Mir SMR system. It groups and configures the various Mir modules that need to work together to implement state machine replication.

func New

func New(

	ownID t.NodeID,

	h host.Host,

	startingCheckpoint *checkpoint.StableCheckpoint,

	crypto mircrypto.Crypto,

	app AppLogic,

	params Params,

	logger logging.Logger,
) (*System, error)

New creates a new SMR system. It instantiates the various Mir modules that make up the system and configures them to work together. The returned system's Start method must be called before the system can be used. The returned system's Stop method should be called when the system is no longer needed. The returned system's Modules method can be used to obtain the Mir modules to be passed to mir.NewNode.

func (*System) Modules

func (sys *System) Modules() modules.Modules

Modules returns the Mir modules that make up the system. The return value of Modules is to be used as an argument to mir.NewNode.

func (*System) Start

func (sys *System) Start() error

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 (*System) Stop

func (sys *System) Stop()

Stop stops the operation of the modules of the SMR system. Currently, it only stops the network transport, as no other modules need to be stopped.

func (*System) WithModule

func (sys *System) WithModule(moduleID t.ModuleID, module modules.Module) *System

WithModule associates the given module ID within the SMR system with the given module. If a module with the given ID already exists, it is replaced. WithModule returns the SMR system itself (not a copy of it), so calls can be chained.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL