Skip to content

Commit 4892ede

Browse files
S1nusConnor O'HaraManav-AggarwalGanesha Upadhyayagupadhyaya
authored
Hardcode centralized sequencer behavior (#1301)
## Overview Goal is to close #1273, #1272, and possibly #1254 and #1270. ## Checklist - [ ] 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 --> ## Summary by CodeRabbit ## Release Notes - **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 <[email protected]> Co-authored-by: Manav Aggarwal <[email protected]> Co-authored-by: Ganesha Upadhyaya <[email protected]> Co-authored-by: Ganesha Upadhyaya <[email protected]>
1 parent 2437b3d commit 4892ede

32 files changed

+355
-1091
lines changed

block/manager.go

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

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

408402
if daHeight > newState.DAHeight {
@@ -564,19 +558,12 @@ func (m *Manager) getCommit(header types.Header) (*types.Commit, error) {
564558

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

579-
return bytes.Equal(m.lastState.Validators.Proposer.PubKey.Bytes(), signerPubBytes), nil
566+
return bytes.Equal(m.genesis.Validators[0].PubKey.Bytes(), signerPubBytes), nil
580567
}
581568

582569
func (m *Manager) publishBlock(ctx context.Context) error {
@@ -627,7 +614,7 @@ func (m *Manager) publishBlock(ctx context.Context) error {
627614
if err != nil {
628615
return nil
629616
}
630-
block.SignedHeader.Header.NextAggregatorsHash = m.getNextAggregatorsHash()
617+
631618
commit, err = m.getCommit(block.SignedHeader.Header)
632619
if err != nil {
633620
return err
@@ -636,8 +623,6 @@ func (m *Manager) publishBlock(ctx context.Context) error {
636623
// set the commit to current block's signed header
637624
block.SignedHeader.Commit = *commit
638625

639-
block.SignedHeader.Validators = m.getLastStateValidators()
640-
641626
// SaveBlock commits the DB tx
642627
err = m.store.SaveBlock(block, commit)
643628
if err != nil {
@@ -657,8 +642,6 @@ func (m *Manager) publishBlock(ctx context.Context) error {
657642
return err
658643
}
659644

660-
block.SignedHeader.Header.NextAggregatorsHash = newState.NextValidators.Hash()
661-
662645
commit, err = m.getCommit(block.SignedHeader.Header)
663646
if err != nil {
664647
return err
@@ -667,8 +650,6 @@ func (m *Manager) publishBlock(ctx context.Context) error {
667650
// set the commit to current block's signed header
668651
block.SignedHeader.Commit = *commit
669652

670-
block.SignedHeader.Validators = m.getLastStateValidators()
671-
672653
// Validate the created block before storing
673654
if err := m.executor.Validate(m.lastState, block); err != nil {
674655
return fmt.Errorf("failed to validate block: %w", err)
@@ -702,12 +683,6 @@ func (m *Manager) publishBlock(ctx context.Context) error {
702683
return err
703684
}
704685

705-
// SaveValidators commits the DB tx
706-
err = m.saveValidatorsToStore(blockHeight)
707-
if err != nil {
708-
return err
709-
}
710-
711686
newState.DAHeight = atomic.LoadUint64(&m.daHeight)
712687
// After this call m.lastState is the NEW state returned from ApplyBlock
713688
// updateState also commits the DB tx
@@ -776,24 +751,6 @@ func (m *Manager) updateState(s types.State) error {
776751
return nil
777752
}
778753

779-
func (m *Manager) saveValidatorsToStore(height uint64) error {
780-
m.lastStateMtx.RLock()
781-
defer m.lastStateMtx.RUnlock()
782-
return m.store.SaveValidators(height, m.lastState.Validators)
783-
}
784-
785-
func (m *Manager) getLastStateValidators() *cmtypes.ValidatorSet {
786-
m.lastStateMtx.RLock()
787-
defer m.lastStateMtx.RUnlock()
788-
return m.lastState.Validators
789-
}
790-
791-
func (m *Manager) getNextAggregatorsHash() types.Hash {
792-
m.lastStateMtx.RLock()
793-
defer m.lastStateMtx.RUnlock()
794-
return m.lastState.NextValidators.Hash()
795-
}
796-
797754
func (m *Manager) getLastBlockTime() time.Time {
798755
m.lastStateMtx.RLock()
799756
defer m.lastStateMtx.RUnlock()
@@ -811,6 +768,7 @@ func (m *Manager) applyBlock(ctx context.Context, block *types.Block) (types.Sta
811768
defer m.lastStateMtx.RUnlock()
812769
return m.executor.ApplyBlock(ctx, m.lastState, block)
813770
}
771+
814772
func updateState(s *types.State, res *abci.ResponseInitChain) {
815773
// If the app did not return an app hash, we keep the one set from the genesis doc in
816774
// the state. We don't set appHash since we don't want the genesis doc app hash
@@ -843,13 +801,4 @@ func updateState(s *types.State, res *abci.ResponseInitChain) {
843801
// We update the last results hash with the empty hash, to conform with RFC-6962.
844802
s.LastResultsHash = merkle.HashFromByteSlices(nil)
845803

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

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
@@ -1377,8 +1377,8 @@ github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4
13771377
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
13781378
github.com/rollkit/celestia-openrpc v0.3.0 h1:jMLsdLNQ7T20yiNDlisBhlyurFOpN1gZ6vC068FPrQA=
13791379
github.com/rollkit/celestia-openrpc v0.3.0/go.mod h1:2ZhU01YF2hsHIROWzxfMZOYM09Kgyy4roH5JWoNJzp0=
1380-
github.com/rollkit/go-da v0.0.0-20231024133951-57bc36006772 h1:0qbVvvxy++RIjwoI2GmqgZDNP5yShBMA+swWjKt7mQE=
1381-
github.com/rollkit/go-da v0.0.0-20231024133951-57bc36006772/go.mod h1:cy1LA9kCyCJHgszKkTh9hJn816l5Oa87GMA2c1imfqA=
1380+
github.com/rollkit/go-da v0.0.0-20231117151938-ee3b613d7a3a h1:d/2491oTlCydpZepyxG66D8s5tT9QG9n4YuemL0eCmQ=
1381+
github.com/rollkit/go-da v0.0.0-20231117151938-ee3b613d7a3a/go.mod h1:cy1LA9kCyCJHgszKkTh9hJn816l5Oa87GMA2c1imfqA=
13821382
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
13831383
github.com/rs/cors v1.8.2/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
13841384
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: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -498,25 +498,28 @@ func (c *FullClient) Commit(ctx context.Context, height *int64) (*ctypes.ResultC
498498
// Validators returns paginated list of validators at given height.
499499
func (c *FullClient) Validators(ctx context.Context, heightPtr *int64, pagePtr, perPagePtr *int) (*ctypes.ResultValidators, error) {
500500
height := c.normalizeHeight(heightPtr)
501-
validators, err := c.node.Store.GetValidators(height)
502-
if err != nil {
503-
return nil, fmt.Errorf("failed to load validators for height %d: %w", height, err)
504-
}
501+
genesisValidators := c.node.GetGenesis().Validators
505502

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

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

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

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

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

0 commit comments

Comments
 (0)