Skip to content

Commit c57dec2

Browse files
S1nusConnor O'HaraManav-AggarwalGanesha Upadhyayagupadhyaya
authored andcommitted
Hardcode centralized sequencer behavior (#1301)
Goal is to close #1273, #1272, and possibly #1254 and #1270. - [ ] New and updated code has appropriate documentation - [ ] New and updated code has new and/or updated testing - [ ] Required CI checks are passing - [ ] Visual proof for any user facing features like CLI or documentation updates - [ ] Linked issues closed with keywords <!-- This is an auto-generated comment: release notes by coderabbit.ai --> - **New Features** - Added a search functionality to the app. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Connor O'Hara <connor@switchboard.xyz> Co-authored-by: Manav Aggarwal <manavaggarwal1234@gmail.com> Co-authored-by: Ganesha Upadhyaya <gupadhyaya@Ganeshas-MacBook-Pro-2.local> Co-authored-by: Ganesha Upadhyaya <ganeshrvce@gmail.com>
1 parent f126599 commit c57dec2

32 files changed

Lines changed: 364 additions & 1130 deletions

block/manager.go

Lines changed: 5 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ func (m *Manager) AggregationLoop(ctx context.Context, lazy bool) {
241241
}
242242
start := time.Now()
243243
err := m.publishBlock(ctx)
244-
if err != nil {
244+
if err != nil && ctx.Err() == nil {
245245
m.logger.Error("error while publishing block", "error", err)
246246
}
247247
timer.Reset(m.getRemainingSleep(start))
@@ -262,7 +262,7 @@ func (m *Manager) AggregationLoop(ctx context.Context, lazy bool) {
262262
case <-timer.C:
263263
// build a block with all the transactions received in the last 1 second
264264
err := m.publishBlock(ctx)
265-
if err != nil {
265+
if err != nil && ctx.Err() == nil {
266266
m.logger.Error("error while publishing block", "error", err)
267267
}
268268
// this can be used to notify multiple subscribers when a block has been built
@@ -396,12 +396,6 @@ func (m *Manager) trySyncNextBlock(ctx context.Context, daHeight uint64) error {
396396
return fmt.Errorf("failed to save block responses: %w", err)
397397
}
398398

399-
// SaveValidators commits the DB tx
400-
err = m.saveValidatorsToStore(bHeight)
401-
if err != nil {
402-
return err
403-
}
404-
405399
m.store.SetHeight(bHeight)
406400

407401
if daHeight > newState.DAHeight {
@@ -563,19 +557,12 @@ func (m *Manager) getCommit(header types.Header) (*types.Commit, error) {
563557

564558
// IsProposer returns whether or not the manager is a proposer
565559
func (m *Manager) IsProposer() (bool, error) {
566-
m.lastStateMtx.RLock()
567-
defer m.lastStateMtx.RUnlock()
568-
// if proposer is not set, assume self proposer
569-
if m.lastState.Validators.Proposer == nil {
570-
return true, nil
571-
}
572-
573560
signerPubBytes, err := m.proposerKey.GetPublic().Raw()
574561
if err != nil {
575562
return false, err
576563
}
577564

578-
return bytes.Equal(m.lastState.Validators.Proposer.PubKey.Bytes(), signerPubBytes), nil
565+
return bytes.Equal(m.genesis.Validators[0].PubKey.Bytes(), signerPubBytes), nil
579566
}
580567

581568
func (m *Manager) publishBlock(ctx context.Context) error {
@@ -629,7 +616,7 @@ func (m *Manager) publishBlock(ctx context.Context) error {
629616
if err != nil {
630617
return nil
631618
}
632-
block.SignedHeader.Header.NextAggregatorsHash = m.getNextAggregatorsHash()
619+
633620
commit, err = m.getCommit(block.SignedHeader.Header)
634621
if err != nil {
635622
return err
@@ -638,8 +625,6 @@ func (m *Manager) publishBlock(ctx context.Context) error {
638625
// set the commit to current block's signed header
639626
block.SignedHeader.Commit = *commit
640627

641-
block.SignedHeader.Validators = m.getLastStateValidators()
642-
643628
// SaveBlock commits the DB tx
644629
err = m.store.SaveBlock(block, commit)
645630
if err != nil {
@@ -659,8 +644,6 @@ func (m *Manager) publishBlock(ctx context.Context) error {
659644
return err
660645
}
661646

662-
block.SignedHeader.Header.NextAggregatorsHash = newState.NextValidators.Hash()
663-
664647
commit, err = m.getCommit(block.SignedHeader.Header)
665648
if err != nil {
666649
return err
@@ -669,8 +652,6 @@ func (m *Manager) publishBlock(ctx context.Context) error {
669652
// set the commit to current block's signed header
670653
block.SignedHeader.Commit = *commit
671654

672-
block.SignedHeader.Validators = m.getLastStateValidators()
673-
674655
// Validate the created block before storing
675656
if err := m.executor.Validate(m.lastState, block); err != nil {
676657
return fmt.Errorf("failed to validate block: %w", err)
@@ -704,12 +685,6 @@ func (m *Manager) publishBlock(ctx context.Context) error {
704685
return err
705686
}
706687

707-
// SaveValidators commits the DB tx
708-
err = m.saveValidatorsToStore(blockHeight)
709-
if err != nil {
710-
return err
711-
}
712-
713688
newState.DAHeight = atomic.LoadUint64(&m.daHeight)
714689
// After this call m.lastState is the NEW state returned from ApplyBlock
715690
// updateState also commits the DB tx
@@ -778,24 +753,6 @@ func (m *Manager) updateState(s types.State) error {
778753
return nil
779754
}
780755

781-
func (m *Manager) saveValidatorsToStore(height uint64) error {
782-
m.lastStateMtx.RLock()
783-
defer m.lastStateMtx.RUnlock()
784-
return m.store.SaveValidators(height, m.lastState.Validators)
785-
}
786-
787-
func (m *Manager) getLastStateValidators() *cmtypes.ValidatorSet {
788-
m.lastStateMtx.RLock()
789-
defer m.lastStateMtx.RUnlock()
790-
return m.lastState.Validators
791-
}
792-
793-
func (m *Manager) getNextAggregatorsHash() types.Hash {
794-
m.lastStateMtx.RLock()
795-
defer m.lastStateMtx.RUnlock()
796-
return m.lastState.NextValidators.Hash()
797-
}
798-
799756
func (m *Manager) getLastBlockTime() time.Time {
800757
m.lastStateMtx.RLock()
801758
defer m.lastStateMtx.RUnlock()
@@ -813,6 +770,7 @@ func (m *Manager) applyBlock(ctx context.Context, block *types.Block) (types.Sta
813770
defer m.lastStateMtx.RUnlock()
814771
return m.executor.ApplyBlock(ctx, m.lastState, block)
815772
}
773+
816774
func updateState(s *types.State, res *abci.ResponseInitChain) {
817775
// If the app did not return an app hash, we keep the one set from the genesis doc in
818776
// the state. We don't set appHash since we don't want the genesis doc app hash
@@ -845,13 +803,4 @@ func updateState(s *types.State, res *abci.ResponseInitChain) {
845803
// We update the last results hash with the empty hash, to conform with RFC-6962.
846804
s.LastResultsHash = merkle.HashFromByteSlices(nil)
847805

848-
if len(res.Validators) > 0 {
849-
vals, err := cmtypes.PB2TM.ValidatorUpdates(res.Validators)
850-
if err != nil {
851-
// TODO(tzdybal): handle error properly
852-
panic(err)
853-
}
854-
s.Validators = cmtypes.NewValidatorSet(vals)
855-
s.NextValidators = cmtypes.NewValidatorSet(vals).CopyIncrementProposerPriority(1)
856-
}
857806
}

block/manager_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,16 @@ import (
2121
)
2222

2323
func TestInitialState(t *testing.T) {
24+
genesisValidators, _ := types.GetGenesisValidatorSetWithSigner()
2425
genesis := &cmtypes.GenesisDoc{
2526
ChainID: "genesis id",
2627
InitialHeight: 100,
28+
Validators: genesisValidators,
2729
}
2830
sampleState := types.State{
2931
ChainID: "state id",
3032
InitialHeight: 123,
3133
LastBlockHeight: 128,
32-
LastValidators: types.GetRandomValidatorSet(),
33-
Validators: types.GetRandomValidatorSet(),
34-
NextValidators: types.GetRandomValidatorSet(),
3534
}
3635

3736
ctx, cancel := context.WithCancel(context.Background())

da/mock/mock.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ func (m *DataAvailabilityLayerClient) SubmitBlocks(ctx context.Context, blocks [
148148
for _, block := range blocks {
149149
blockHeight := uint64(block.Height())
150150
m.logger.Debug("Submitting blocks to DA layer!", "height", blockHeight, "dataLayerHeight", daHeight)
151-
152151
hash := block.Hash()
153152
blob, err := block.MarshalBinary()
154153
if err != nil {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ require (
2424
github.com/multiformats/go-multiaddr v0.12.0
2525
github.com/prometheus/client_golang v1.17.0
2626
github.com/rollkit/celestia-openrpc v0.3.0
27-
github.com/rollkit/go-da v0.0.0-20231024133951-57bc36006772
27+
github.com/rollkit/go-da v0.0.0-20231117151938-ee3b613d7a3a
2828
github.com/rs/cors v1.10.1
2929
github.com/spf13/cobra v1.8.0
3030
github.com/spf13/viper v1.17.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,8 +1391,8 @@ github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDN
13911391
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
13921392
github.com/rollkit/celestia-openrpc v0.3.0 h1:jMLsdLNQ7T20yiNDlisBhlyurFOpN1gZ6vC068FPrQA=
13931393
github.com/rollkit/celestia-openrpc v0.3.0/go.mod h1:2ZhU01YF2hsHIROWzxfMZOYM09Kgyy4roH5JWoNJzp0=
1394-
github.com/rollkit/go-da v0.0.0-20231024133951-57bc36006772 h1:0qbVvvxy++RIjwoI2GmqgZDNP5yShBMA+swWjKt7mQE=
1395-
github.com/rollkit/go-da v0.0.0-20231024133951-57bc36006772/go.mod h1:cy1LA9kCyCJHgszKkTh9hJn816l5Oa87GMA2c1imfqA=
1394+
github.com/rollkit/go-da v0.0.0-20231117151938-ee3b613d7a3a h1:d/2491oTlCydpZepyxG66D8s5tT9QG9n4YuemL0eCmQ=
1395+
github.com/rollkit/go-da v0.0.0-20231117151938-ee3b613d7a3a/go.mod h1:cy1LA9kCyCJHgszKkTh9hJn816l5Oa87GMA2c1imfqA=
13961396
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
13971397
github.com/rs/cors v1.8.2/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
13981398
github.com/rs/cors v1.10.1 h1:L0uuZVXIKlI1SShY2nhFfo44TYvDPQ1w4oFkUJNfhyo=

node/crypto.go

Lines changed: 0 additions & 31 deletions
This file was deleted.

node/crypto_test.go

Lines changed: 0 additions & 52 deletions
This file was deleted.

node/full_client.go

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ func (c *FullClient) BlockResults(ctx context.Context, height *int64) (*ctypes.R
457457
} else {
458458
h = uint64(*height)
459459
}
460-
block, err := c.node.Store.LoadBlock(h)
460+
block, err := c.node.Store.GetBlock(h)
461461
if err != nil {
462462
return nil, err
463463
}
@@ -499,25 +499,28 @@ func (c *FullClient) Commit(ctx context.Context, height *int64) (*ctypes.ResultC
499499
// Validators returns paginated list of validators at given height.
500500
func (c *FullClient) Validators(ctx context.Context, heightPtr *int64, pagePtr, perPagePtr *int) (*ctypes.ResultValidators, error) {
501501
height := c.normalizeHeight(heightPtr)
502-
validators, err := c.node.Store.GetValidators(height)
503-
if err != nil {
504-
return nil, fmt.Errorf("failed to load validators for height %d: %w", height, err)
505-
}
502+
genesisValidators := c.node.GetGenesis().Validators
506503

507-
totalCount := len(validators.Validators)
508-
perPage := validatePerPage(perPagePtr)
509-
page, err := validatePage(pagePtr, perPage, totalCount)
510-
if err != nil {
511-
return nil, err
504+
if len(genesisValidators) != 1 {
505+
return nil, fmt.Errorf("there should be exactly one validator in genesis")
506+
}
507+
// Since it's a centralized sequencer
508+
// changed behavior to get this from genesis
509+
genesisValidator := genesisValidators[0]
510+
validator := cmtypes.Validator{
511+
Address: genesisValidator.Address,
512+
PubKey: genesisValidator.PubKey,
513+
VotingPower: int64(1),
514+
ProposerPriority: int64(1),
512515
}
513516

514-
skipCount := validateSkipCount(page, perPage)
515-
v := validators.Validators[skipCount : skipCount+min(perPage, totalCount-skipCount)]
516517
return &ctypes.ResultValidators{
517518
BlockHeight: int64(height),
518-
Validators: v,
519-
Count: len(v),
520-
Total: totalCount,
519+
Validators: []*cmtypes.Validator{
520+
&validator,
521+
},
522+
Count: 1,
523+
Total: 1,
521524
}, nil
522525
}
523526

@@ -697,11 +700,20 @@ func (c *FullClient) Status(ctx context.Context) (*ctypes.ResultStatus, error) {
697700
return nil, fmt.Errorf("failed to find earliest block: %w", err)
698701
}
699702

700-
validators, err := c.node.Store.GetValidators(latest.Height())
701-
if err != nil {
702-
return nil, fmt.Errorf("failed to fetch the validator info at latest block: %w", err)
703+
genesisValidators := c.node.GetGenesis().Validators
704+
705+
if len(genesisValidators) != 1 {
706+
return nil, fmt.Errorf("there should be exactly one validator in genesis")
707+
}
708+
709+
// Changed behavior to get this from genesis
710+
genesisValidator := genesisValidators[0]
711+
validator := cmtypes.Validator{
712+
Address: genesisValidator.Address,
713+
PubKey: genesisValidator.PubKey,
714+
VotingPower: int64(1),
715+
ProposerPriority: int64(1),
703716
}
704-
_, validator := validators.GetByAddress(latest.SignedHeader.ProposerAddress)
705717

706718
state, err := c.node.Store.GetState()
707719
if err != nil {

0 commit comments

Comments
 (0)