Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 276
fork-choice interface#767
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
c539a68cd946f4439b1123831a1f8195ea546735b500e672e194e737bf1c2b23b01806c4b27871e0f14108b28977d71de021b5fcaffb66b0704b2c3fc2bc698f01985023432695b08e7fa46759d39d9ecFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -19,6 +19,7 @@ import ( | ||
| "github.com/rollkit/rollkit/config" | ||
| "github.com/rollkit/rollkit/da" | ||
| "github.com/rollkit/rollkit/fork_choice" | ||
| "github.com/rollkit/rollkit/log" | ||
| "github.com/rollkit/rollkit/mempool" | ||
| "github.com/rollkit/rollkit/state" | ||
| @@ -63,7 +64,7 @@ type Manager struct { | ||
| FraudProofInCh chan *abci.FraudProof | ||
| blockInCh chan newBlockEvent | ||
| syncCache map[uint64]*types.Block | ||
| syncCache map[uint64][]*types.Block | ||
| // retrieveMtx is used by retrieveCond | ||
| retrieveMtx *sync.Mutex | ||
| @@ -74,6 +75,7 @@ type Manager struct { | ||
| logger log.Logger | ||
| fcr fork_choice.ForkChoiceRule | ||
| // For usage by Lazy Aggregator mode | ||
| buildingBlock bool | ||
| txsAvailable <-chan struct{} | ||
| @@ -133,6 +135,13 @@ func NewManager( | ||
| } | ||
| } | ||
| fcr, ok := fork_choice.GetRule(conf.ForkChoiceRule) | ||
| if !ok { | ||
| fcr, ok = fork_choice.GetRule(config.DefaultNodeConfig.BlockManagerConfig.ForkChoiceRule) | ||
| if !ok { | ||
| panic("Invalid default fork-choice rule") | ||
| } | ||
| } | ||
| var txsAvailableCh <-chan struct{} | ||
| if mempool != nil { | ||
| txsAvailableCh = mempool.TxsAvailable() | ||
| @@ -155,9 +164,10 @@ func NewManager( | ||
| blockInCh: make(chan newBlockEvent, 100), | ||
| FraudProofInCh: make(chan *abci.FraudProof, 100), | ||
| retrieveMtx: new(sync.Mutex), | ||
| syncCache: make(map[uint64][]*types.Block), | ||
| lastStateMtx: new(sync.Mutex), | ||
| syncCache: make(map[uint64]*types.Block), | ||
| logger: logger, | ||
| fcr: fcr, | ||
| txsAvailable: txsAvailableCh, | ||
| doneBuildingBlock: doneBuildingCh, | ||
| buildingBlock: false, | ||
| @@ -267,7 +277,10 @@ func (m *Manager) SyncLoop(ctx context.Context, cancel context.CancelFunc) { | ||
| "daHeight", daHeight, | ||
| "hash", block.Hash(), | ||
| ) | ||
| m.syncCache[block.SignedHeader.Header.BaseHeader.Height] = block | ||
| if m.syncCache[block.SignedHeader.Header.BaseHeader.Height] == nil { | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
| ||
| m.syncCache[block.SignedHeader.Header.BaseHeader.Height] = make([]*types.Block, 1) | ||
| } | ||
| m.syncCache[block.SignedHeader.Header.BaseHeader.Height] = append(m.syncCache[block.SignedHeader.Header.BaseHeader.Height], block) | ||
| m.retrieveCond.Signal() | ||
| err := m.trySyncNextBlock(ctx, daHeight) | ||
| @@ -313,8 +326,7 @@ func (m *Manager) SyncLoop(ctx context.Context, cancel context.CancelFunc) { | ||
| func (m *Manager) trySyncNextBlock(ctx context.Context, daHeight uint64) error { | ||
| var commit *types.Commit | ||
| currentHeight := m.store.Height() // TODO(tzdybal): maybe store a copy in memory | ||
| b, ok := m.syncCache[currentHeight+1] | ||
| b, ok := m.fcr.Apply(m.syncCache[currentHeight+1]) | ||
| if !ok { | ||
| return nil | ||
| } | ||
| @@ -621,7 +633,7 @@ func (m *Manager) submitBlockToDA(ctx context.Context, block *types.Block) error | ||
| } | ||
| if !submitted { | ||
| return fmt.Errorf("Failed to submit block to DA layer after %d attempts", maxSubmitAttempts) | ||
| return fmt.Errorf("failed to submit block to DA layer after %d attempts", maxSubmitAttempts) | ||
| } | ||
| return nil | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package fork_choice | ||
| import "github.com/rollkit/rollkit/types" | ||
| var _ ForkChoiceRule = firstOrderedPure{} | ||
| type firstOrderedPure struct{} | ||
| func (f firstOrderedPure) Apply(candidates []*types.Block) (*types.Block, bool) { | ||
| // Return first non-nil block from the candidates | ||
| for _, b := range candidates { | ||
| if b != nil { | ||
| return b, true | ||
| } | ||
| } | ||
| return nil, false | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package fork_choice | ||
| import ( | ||
| "github.com/rollkit/rollkit/types" | ||
| ) | ||
| const ( | ||
| //FirstOrderedCentralized = "FOC" | ||
| FirstOrderedPure = "FOP" | ||
| //HighestGasPure = "HGP" | ||
| //Astria = "ASTRIA" | ||
| ) | ||
| func GetRule(ruleName string) (ForkChoiceRule, bool) { | ||
| switch ruleName { | ||
| case FirstOrderedPure: | ||
| return firstOrderedPure{}, true | ||
| default: | ||
| return nil, false | ||
| } | ||
| } | ||
| type ForkChoiceRule interface { | ||
| Apply(candidates []*types.Block) (*types.Block, bool) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
multiple calls to
GetRuleis not needed. when!oksimply assignfirstOrderedPuretofcr?