Skip to content

Commit

Permalink
Support for non aggregator mode (#155)
Browse files Browse the repository at this point in the history
* Changed default value of aggregator to prevent a bug where it's always set as true.

* Changed some dymension config flags to be optional for non-aggregator mode.

* Fixed a bug where SLStateIndex wouldn't get updated.

* Enhanced logging messages on p2p and dymension client.
  • Loading branch information
omritoptix authored Dec 6, 2022
1 parent 9eaa582 commit 1ab3c5e
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 56 deletions.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (nc *NodeConfig) GetViperConfig(v *viper.Viper) error {
func AddFlags(cmd *cobra.Command) {
def := DefaultNodeConfig

cmd.Flags().Bool(flagAggregator, def.Aggregator, "run node in aggregator mode")
cmd.Flags().Bool(flagAggregator, false, "run node in aggregator mode")
cmd.Flags().String(flagDALayer, def.DALayer, "Data Availability Layer Client name (mock or grpc")
cmd.Flags().String(flagDAConfig, def.DAConfig, "Data Availability Layer Client config")
cmd.Flags().String(flagSettlementLayer, def.SettlementLayer, "Settlement Layer Client name (currently only mock)")
Expand Down
3 changes: 3 additions & 0 deletions p2p/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,13 @@ func (c *Client) findPeers(ctx context.Context) error {

// tryConnect attempts to connect to a peer and logs error if necessary
func (c *Client) tryConnect(ctx context.Context, peer peer.AddrInfo) {
c.logger.Debug("trying to connect to peer", "peer", peer)
err := c.host.Connect(ctx, peer)
if err != nil {
c.logger.Error("failed to connect to peer", "peer", peer, "error", err)
return
}
c.logger.Debug("connected to peer", "peer", peer)
}

func (c *Client) setupGossiping(ctx context.Context) error {
Expand Down
2 changes: 1 addition & 1 deletion proto/types/dymint/state.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ message State {
tendermint.types.BlockID last_block_id = 5 [(gogoproto.nullable) = false, (gogoproto.customname) = "LastBlockID"];
google.protobuf.Timestamp last_block_time = 6 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];

uint64 da_height = 7 [(gogoproto.customname) = "DAHeight"];
uint64 sl_state_index = 7 [(gogoproto.customname) = "SLStateIndex"];

tendermint.types.ValidatorSet next_validators = 8;
tendermint.types.ValidatorSet validators = 9;
Expand Down
20 changes: 15 additions & 5 deletions settlement/dymension.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ func (d *DymensionLayerClient) Init(config []byte, pubsub *pubsub.Server, logger
d.ctx, d.cancel = context.WithCancel(context.Background())
client, err := cosmosclient.New(
d.ctx,
cosmosclient.WithAddressPrefix(addressPrefix),
cosmosclient.WithNodeAddress(c.NodeAddress),
cosmosclient.WithKeyringBackend(c.KeyringBackend),
cosmosclient.WithHome(c.KeyRingHomeDir),
d.getCosmosClientOptions(d.config)...,
)
if err != nil {
return err
Expand Down Expand Up @@ -112,6 +109,19 @@ func (d *DymensionLayerClient) getConfig(config []byte) (*Config, error) {
return c, nil
}

func (d *DymensionLayerClient) getCosmosClientOptions(c Config) []cosmosclient.Option {
options := []cosmosclient.Option{
cosmosclient.WithAddressPrefix(addressPrefix),
cosmosclient.WithNodeAddress(d.config.NodeAddress),
}
if d.config.KeyringBackend != "" {
options = append(options,
cosmosclient.WithKeyringBackend(d.config.KeyringBackend),
cosmosclient.WithHome(d.config.KeyRingHomeDir))
}
return options
}

// Start is called once, after init. It initializes the query client.
func (d *DymensionLayerClient) Start() error {
d.logger.Debug("settlement Layer Client starting.")
Expand Down Expand Up @@ -286,7 +296,7 @@ func (d *DymensionLayerClient) SubmitBatch(batch *types.Batch, daClient da.Clien
func (d *DymensionLayerClient) RetrieveBatch(stateIndex ...uint64) (*ResultRetrieveBatch, error) {
var stateInfo rollapptypes.StateInfo
if len(stateIndex) == 0 {
d.logger.Debug("Getting latest batch from settlement layer", "latest height", d.latestHeight)
d.logger.Debug("Getting latest batch from settlement layer")
latestStateInfoIndexResp, err := d.rollappQueryClient.LatestStateInfoIndex(d.ctx,
&rollapptypes.QueryGetLatestStateInfoIndexRequest{RollappId: d.config.RollappID})
if latestStateInfoIndexResp == nil {
Expand Down
98 changes: 49 additions & 49 deletions types/pb/dymint/state.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions types/serialization.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ func (s *State) ToProto() (*pb.State, error) {
ChainId: s.ChainID,
InitialHeight: s.InitialHeight,
LastBlockHeight: s.LastBlockHeight,
SLStateIndex: s.SLStateIndex,
LastBlockID: s.LastBlockID.ToProto(),
LastBlockTime: s.LastBlockTime,
NextValidators: nextValidators,
Expand All @@ -263,6 +264,7 @@ func (s *State) FromProto(other *pb.State) error {
s.ChainID = other.ChainId
s.InitialHeight = other.InitialHeight
s.LastBlockHeight = other.LastBlockHeight
s.SLStateIndex = other.SLStateIndex
lastBlockID, err := types.BlockIDFromProto(&other.LastBlockID)
if err != nil {
return err
Expand Down

0 comments on commit 1ab3c5e

Please sign in to comment.