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

feat(manager): create sequencer events populate sequencers list #1102

Merged
merged 8 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
/* ----------------------------- sequencer mode ----------------------------- */
// Subscribe to batch events, to update last submitted height in case batch confirmation was lost. This could happen if the sequencer crash/restarted just after submitting a batch to the settlement and by the time we query the last batch, this batch wasn't accepted yet.
go uevent.MustSubscribe(ctx, m.Pubsub, "updateSubmittedHeightLoop", settlement.EventQueryNewSettlementBatchAccepted, m.UpdateLastSubmittedHeight, m.logger)
go uevent.MustSubscribe(ctx, m.Pubsub, "newBondedSequencer", settlement.EventQueryNewBondedSequencer, m.UpdateSequencerSet, m.logger)
Dismissed Show dismissed Hide dismissed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about full node mode? probably required there as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, moved to before to be called by sequencers and full-nodes


// Sequencer must wait till DA is synced to start submitting blobs
<-m.DAClient.Synced()
Expand Down
25 changes: 25 additions & 0 deletions block/sequencers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/dymensionxyz/dymint/settlement"
"github.com/dymensionxyz/dymint/types"
"github.com/tendermint/tendermint/libs/pubsub"
)

func (m *Manager) MonitorSequencerRotation(ctx context.Context, rotateC chan string) error {
Expand Down Expand Up @@ -179,3 +180,27 @@ func (m *Manager) UpdateProposer() error {
m.State.Sequencers.SetProposer(m.SLClient.GetProposer())
return nil
}

// UpdateLastSubmittedHeight will update last height submitted height upon events.
// This may be necessary in case we crashed/restarted before getting response for our submission to the settlement layer.
func (m *Manager) UpdateSequencerSet(event pubsub.Message) {
eventData, ok := event.Data().(*settlement.EventDataNewBondedSequencer)
if !ok {
m.logger.Error("onReceivedBatch", "err", "wrong event data received")
return
}

if m.State.Sequencers.GetByAddress(eventData.SeqAddr) != nil {
m.logger.Debug("Sequencer not added from new bonded sequencer event because already in the list.")
return
}

newSequencer, err := m.SLClient.GetSequencerByAddress(eventData.SeqAddr)
if err != nil {
m.logger.Error("Unable to add new sequencer from event. err:%w", err)
return
}
sequencers := m.State.Sequencers.Sequencers
sequencers = append(sequencers, newSequencer)
srene marked this conversation as resolved.
Show resolved Hide resolved
m.State.Sequencers.SetSequencers(sequencers)
}

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

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

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

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

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

41 changes: 21 additions & 20 deletions mocks/github.com/dymensionxyz/dymint/store/mock_Store.go

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

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

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

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

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

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

40 changes: 40 additions & 0 deletions settlement/dymension/dymension.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,46 @@ func (c *Client) GetProposer() *types.Sequencer {
return &seqs[index]
}

// GetSequencerByAddress returns a sequencer by its address.
func (c *Client) GetSequencerByAddress(address string) (types.Sequencer, error) {
var res *sequencertypes.QueryGetSequencerResponse
req := &sequencertypes.QueryGetSequencerRequest{
SequencerAddress: address,
}

err := c.RunWithRetry(func() error {
var err error
res, err = c.sequencerQueryClient.Sequencer(c.ctx, req)
if err == nil {
return nil
}

if status.Code(err) == codes.NotFound {
return retry.Unrecoverable(errors.Join(gerrc.ErrNotFound, err))
}
return err
})

if err != nil {
return types.Sequencer{}, err
}

var pubKey cryptotypes.PubKey
err = c.protoCodec.UnpackAny(res.Sequencer.DymintPubKey, &pubKey)
if err != nil {
return types.Sequencer{}, err
}

tmPubKey, err := cryptocodec.ToTmPubKeyInterface(pubKey)
if err != nil {
return types.Sequencer{}, err
}

sequencer := *types.NewSequencer(tmPubKey, res.Sequencer.Address)

return sequencer, nil
}

// GetAllSequencers returns all sequencers of the given rollapp.
func (c *Client) GetAllSequencers() ([]types.Sequencer, error) {
var res *sequencertypes.QueryGetSequencersByRollappResponse
Expand Down
5 changes: 5 additions & 0 deletions settlement/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ func (c *Client) GetProposer() *types.Sequencer {
return types.NewSequencer(tmPubKey, pubKey.Address().String())
}

// GetSequencerByAddress returns all sequencer information by its address. Not implemented since it will not be used in grpc SL
func (c *Client) GetSequencerByAddress(address string) (types.Sequencer, error) {
return types.Sequencer{}, nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to return error with empty sequencer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added panic because it shouldnt be called from grpc sl

}

// GetAllSequencers implements settlement.ClientI.
func (c *Client) GetAllSequencers() ([]types.Sequencer, error) {
return c.GetBondedSequencers()
Expand Down
5 changes: 5 additions & 0 deletions settlement/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ func (c *Client) GetProposer() *types.Sequencer {
return types.NewSequencer(tmPubKey, pubKey.Address().String())
}

// GetSequencerByAddress returns all sequencer information by its address. Not implemented since it will not be used in mock SL
func (c *Client) GetSequencerByAddress(address string) (types.Sequencer, error) {
return types.Sequencer{}, nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to return error with empty sequencer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added panic because it shouldnt be called from mock sl

}

// GetAllSequencers implements settlement.ClientI.
func (c *Client) GetAllSequencers() ([]types.Sequencer, error) {
return c.GetBondedSequencers()
Expand Down
3 changes: 2 additions & 1 deletion settlement/settlement.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ type ClientI interface {
GetLatestBatch() (*ResultRetrieveBatch, error)
// GetBatchAtIndex returns the batch at the given index.
GetBatchAtIndex(index uint64) (*ResultRetrieveBatch, error)

// GetSequencerByAddress returns all sequencer information by its address.
GetSequencerByAddress(address string) (types.Sequencer, error)
// GetAllSequencers returns all sequencers for this rollapp (bonded and not bonded).
GetAllSequencers() ([]types.Sequencer, error)
// GetBondedSequencers returns the list of the bonded sequencers for this rollapp.
Expand Down
Loading