Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove active sequencer nodetype #2254

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion go/common/host/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ func NewIdentity(cfg *hostconfig.HostConfig) Identity {
ID: cfg.ID,
P2PPublicAddress: cfg.P2PPublicAddress,
IsGenesis: cfg.IsGenesis,
IsSequencer: cfg.NodeType == common.ActiveSequencer,
IsSequencer: cfg.NodeType == common.Sequencer,
}
}
24 changes: 9 additions & 15 deletions go/common/node_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,26 @@ package common
import "fmt"

const (
activeSequencer = "sequencer"
validator = "validator"
backupSequencer = "backup_sequencer"
unknown = "unknown"
sequencer = "sequencer"
validator = "validator"
unknown = "unknown"
)

// NodeType represents the type of the node.
type NodeType int

const (
ActiveSequencer NodeType = iota
Validator
BackupSequencer
Validator NodeType = iota
Sequencer
Unknown
)

func (n NodeType) String() string {
switch n {
case ActiveSequencer:
return activeSequencer
case Validator:
return validator
case BackupSequencer:
return backupSequencer
case Sequencer:
return sequencer
case Unknown:
return unknown
default:
Expand All @@ -45,12 +41,10 @@ func (n *NodeType) UnmarshalText(text []byte) error {

func ToNodeType(s string) (NodeType, error) {
switch s {
case activeSequencer:
return ActiveSequencer, nil
case validator:
return Validator, nil
case backupSequencer:
return BackupSequencer, nil
case sequencer:
return Sequencer, nil
default:
return Unknown, fmt.Errorf("string '%s' cannot be converted to a node type", s)
}
Expand Down
18 changes: 7 additions & 11 deletions go/enclave/enclave_admin_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type enclaveAdminService struct {
enclaveKeyService *crypto.EnclaveAttestedKeyService
mempool *components.TxPool
sharedSecretService *crypto.SharedSecretService
activeSequencer bool
}

func NewEnclaveAdminAPI(config *enclaveconfig.EnclaveConfig, storage storage.Storage, logger gethlog.Logger, blockProcessor components.L1BlockProcessor, registry components.BatchRegistry, batchExecutor components.BatchExecutor, gethEncodingService gethencoding.EncodingService, stopControl *stopcontrol.StopControl, subscriptionManager *events.SubscriptionManager, enclaveKeyService *crypto.EnclaveAttestedKeyService, mempool *components.TxPool, chainConfig *params.ChainConfig, mgmtContractLib mgmtcontractlib.MgmtContractLib, attestationProvider components.AttestationProvider, sharedSecretService *crypto.SharedSecretService, daEncryptionService *crypto.DAEncryptionService) common.EnclaveAdmin {
Expand Down Expand Up @@ -119,17 +120,14 @@ func NewEnclaveAdminAPI(config *enclaveconfig.EnclaveConfig, storage storage.Sto
if eas.isBackupSequencer(context.Background()) || eas.isActiveSequencer(context.Background()) {
mempool.SetValidateMode(false)
}
if eas.isActiveSequencer(context.Background()) {
eas.service = sequencerService
}

return eas
}

// addSequencer is used internally to add a sequencer enclaveID to the pool of attested enclaves.
// If it is the current enclave it will change the behaviour of this enclave to be a backup sequencer (ready to become active).
func (e *enclaveAdminService) addSequencer(id common.EnclaveID, _ types.Receipt) common.SystemError {
err := e.storage.StoreNodeType(context.Background(), id, common.BackupSequencer)
err := e.storage.StoreNodeType(context.Background(), id, common.Sequencer)
if err != nil {
return responses.ToInternalError(err)
}
Expand All @@ -150,12 +148,10 @@ func (e *enclaveAdminService) MakeActive() common.SystemError {
return fmt.Errorf("only backup sequencer can become active")
}

err := e.storage.StoreNodeType(context.Background(), e.enclaveKeyService.EnclaveID(), common.ActiveSequencer)
if err != nil {
return err
}

e.activeSequencer = true
e.service = e.sequencerService
e.logger.Info("Enclave is now active sequencer.")

return nil
}

Expand Down Expand Up @@ -541,11 +537,11 @@ func (e *enclaveAdminService) sequencer() nodetype.ActiveSequencer {
}

func (e *enclaveAdminService) isActiveSequencer(ctx context.Context) bool {
return e.getNodeType(ctx) == common.ActiveSequencer
return e.activeSequencer && e.getNodeType(ctx) == common.Sequencer
}

func (e *enclaveAdminService) isBackupSequencer(ctx context.Context) bool {
return e.getNodeType(ctx) == common.BackupSequencer
return e.getNodeType(ctx) == common.Sequencer && !e.activeSequencer
}

func (e *enclaveAdminService) isValidator(ctx context.Context) bool { //nolint:unused
Expand Down
4 changes: 2 additions & 2 deletions go/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,10 @@ func (h *host) NewHeadsChan() chan *common.BatchHeader {

// Checks the host config is valid.
func (h *host) validateConfig() {
if h.config.IsGenesis && h.config.NodeType != common.ActiveSequencer {
if h.config.IsGenesis && h.config.NodeType != common.Sequencer {
h.logger.Crit("genesis node must be the sequencer")
}
if !h.config.IsGenesis && h.config.NodeType == common.ActiveSequencer {
if !h.config.IsGenesis && h.config.NodeType == common.Sequencer {
h.logger.Crit("only the genesis node can be a sequencer")
}

Expand Down
2 changes: 1 addition & 1 deletion go/host/l2/batchrepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func NewBatchRepository(cfg *hostconfig.HostConfig, hostService batchRepoService
validatedBatchSubscribers: subscription.NewManager[host.L2BatchHandler](),
sl: hostService,
storage: storage,
isSequencer: cfg.NodeType == common.ActiveSequencer,
isSequencer: cfg.NodeType == common.Sequencer,
latestBatchSeqNo: big.NewInt(0),
latestValidatedSeqNo: big.NewInt(0),
running: atomic.Bool{},
Expand Down
2 changes: 1 addition & 1 deletion go/host/p2p/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func NewSocketP2PLayer(config *hostconfig.HostConfig, serviceLocator p2pServiceL
stopControl: stopcontrol.New(),
sl: serviceLocator,

isSequencer: config.NodeType == common.ActiveSequencer,
isSequencer: config.NodeType == common.Sequencer,
ourBindAddress: config.P2PBindAddress,
ourPublicAddress: config.P2PPublicAddress,
sequencerAddress: config.SequencerP2PAddress,
Expand Down
2 changes: 1 addition & 1 deletion go/node/cmd/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func NodeCLIConfigToTenConfig(cliCfg *NodeConfigCLI) *config.TenConfig {

// the sequencer does not store the executed transactions
// todo - once we replace this launcher we'll configure this flag explicitly via an environment variable
if nodeType == common.ActiveSequencer {
if nodeType == common.Sequencer {
tenCfg.Enclave.StoreExecutedTransactions = false
}

Expand Down
2 changes: 1 addition & 1 deletion integration/simulation/devnetwork/dev_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (s *InMemDevNetwork) GetGatewayClient() (ethadapter.EthClient, error) {
func (s *InMemDevNetwork) startNodes() {
if s.tenSequencer == nil {
// initialise node operators (sequencer is node 0, validators are 1..N)
s.tenSequencer = NewInMemNodeOperator(0, s.tenConfig, common.ActiveSequencer, s.l1SetupData, s.l1Network.GetClient(0), s.networkWallets.NodeWallets[0], s.logger)
s.tenSequencer = NewInMemNodeOperator(0, s.tenConfig, common.Sequencer, s.l1SetupData, s.l1Network.GetClient(0), s.networkWallets.NodeWallets[0], s.logger)
for i := 1; i <= s.tenConfig.InitNumValidators; i++ {
l1Client := s.l1Network.GetClient(i % s.l1Network.NumNodes())
s.tenValidators = append(s.tenValidators, NewInMemNodeOperator(i, s.tenConfig, common.Validator, s.l1SetupData, l1Client, s.networkWallets.NodeWallets[i], s.logger))
Expand Down
8 changes: 4 additions & 4 deletions integration/simulation/devnetwork/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (n *InMemNodeOperator) StopHost() error {
func (n *InMemNodeOperator) Start() error {
var err error
numEnclaves := n.config.NumSeqEnclaves
if n.nodeType != common.ActiveSequencer {
if n.nodeType != common.Sequencer {
numEnclaves = 1
}
n.enclaves = make([]*enclavecontainer.EnclaveContainer, numEnclaves)
Expand Down Expand Up @@ -115,7 +115,7 @@ func (n *InMemNodeOperator) StartEnclave(idx int) error {
func (n *InMemNodeOperator) createHostContainer() *hostcontainer.HostContainer {
enclavePort := n.config.PortStart + integration.DefaultEnclaveOffset + n.operatorIdx
var enclaveAddresses []string
if n.nodeType == common.ActiveSequencer {
if n.nodeType == common.Sequencer {
for i := 0; i < n.config.NumSeqEnclaves; i++ {
enclaveAddresses = append(enclaveAddresses, fmt.Sprintf("%s:%d", network.Localhost, enclavePort+(i*_multiEnclaveOffset)))
}
Expand All @@ -129,7 +129,7 @@ func (n *InMemNodeOperator) createHostContainer() *hostcontainer.HostContainer {

hostConfig := &hostconfig.HostConfig{
ID: fmt.Sprintf("%d", n.operatorIdx),
IsGenesis: n.nodeType == common.ActiveSequencer,
IsGenesis: n.nodeType == common.Sequencer,
NodeType: n.nodeType,
HasClientRPCHTTP: true,
ClientRPCPortHTTP: uint64(n.config.PortStart + integration.DefaultHostRPCHTTPOffset + n.operatorIdx),
Expand Down Expand Up @@ -272,7 +272,7 @@ func NewInMemNodeOperator(operatorIdx int, config *TenConfig, nodeType common.No
) *InMemNodeOperator {
// todo (@matt) - put sqlite and levelDB storage in the same temp dir
numEnclaves := config.NumSeqEnclaves
if nodeType != common.ActiveSequencer {
if nodeType != common.Sequencer {
numEnclaves = 1
}
sqliteDBPaths := make([]string, numEnclaves)
Expand Down
2 changes: 1 addition & 1 deletion integration/simulation/network/obscuro_node_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func isAddressAvailable(address string) bool {
func GetNodeType(i int) common.NodeType {
// Only the genesis node is assigned the role of sequencer.
if i == 0 {
return common.ActiveSequencer
return common.Sequencer
}
return common.Validator
}
Loading