Skip to content

Commit

Permalink
steps: rename StepIrreversible to StepFinal, and StepStalled to StepS…
Browse files Browse the repository at this point in the history
…tale
  • Loading branch information
colindickson committed Sep 8, 2022
1 parent b462cf2 commit 6c4cb8d
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 81 deletions.
6 changes: 3 additions & 3 deletions cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var EmptyCursor = &Cursor{
}

func (c *Cursor) IsOnFinalBlock() bool {
return c.Block.Num() == c.LIB.Num() && c.Step.Matches(StepIrreversible)
return c.Block.Num() == c.LIB.Num() && c.Step.Matches(StepFinal)
}

func (c *Cursor) ToOpaque() string {
Expand Down Expand Up @@ -191,8 +191,8 @@ func readCursorStep(part string) (StepType, error) {

if out != StepNew &&
out != StepUndo &&
out != StepIrreversible &&
out != StepNewIrreversible {
out != StepFinal &&
out != StepNewFinal {
return 0, fmt.Errorf("invalid step: %d", step)
}

Expand Down
6 changes: 3 additions & 3 deletions cursor_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (f *cursorResolver) ProcessBlock(blk *Block, obj interface{}) error {
if blk.Number == f.cursor.Block.Num() {
f.mergedBlocksSeen = append(f.mergedBlocksSeen, &BlockWithObj{blk, obj})
if blk.Id == f.cursor.Block.ID() {
if err := f.sendMergedBlocksBetween(StepIrreversible, f.cursor.LIB.Num(), f.cursor.Block.Num()); err != nil {
if err := f.sendMergedBlocksBetween(StepFinal, f.cursor.LIB.Num(), f.cursor.Block.Num()); err != nil {
return err
}
f.passthrough = true
Expand All @@ -67,10 +67,10 @@ func (f *cursorResolver) ProcessBlock(blk *Block, obj interface{}) error {
if err := f.sendUndoBlocks(undoBlocks); err != nil {
return err
}
if err := f.sendMergedBlocksBetween(StepIrreversible, f.cursor.LIB.Num(), continueAfter); err != nil {
if err := f.sendMergedBlocksBetween(StepFinal, f.cursor.LIB.Num(), continueAfter); err != nil {
return err
}
if err := f.sendMergedBlocksBetween(StepNewIrreversible, continueAfter, blk.Number); err != nil {
if err := f.sendMergedBlocksBetween(StepNewFinal, continueAfter, blk.Number); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion filesource.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ func (s *FileSource) preprocess(block *Block, out chan *PreprocessedBlock) {
obj = &wrappedObject{
obj: obj,
cursor: &Cursor{
Step: StepNewIrreversible,
Step: StepNewFinal,
Block: block.AsRef(),
LIB: block.AsRef(),
HeadBlock: block.AsRef(),
Expand Down
6 changes: 3 additions & 3 deletions filesource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ func TestFileSourceFromCursor(t *testing.T) {
{id: "104a", num: 104},
}
expectedSteps := []StepType{
StepIrreversible,
StepNewIrreversible,
StepFinal,
StepNewFinal,
}
testDone := make(chan interface{})
handlerCount := 0
Expand All @@ -138,7 +138,7 @@ func TestFileSourceFromCursor(t *testing.T) {
})

fs := NewFileSourceFromCursor(bs, nil, &Cursor{
Step: StepNewIrreversible,
Step: StepNewFinal,
Block: NewBlockRef("3a", 3),
HeadBlock: NewBlockRef("3a", 3),
LIB: NewBlockRef("2a", 2),
Expand Down
20 changes: 10 additions & 10 deletions forkable/forkable.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (p *Forkable) blocksFromNum(num uint64) ([]*bstream.PreprocessedBlock, erro
}
step := bstream.StepNew
if ref.Num() <= libNum {
step = bstream.StepNewIrreversible
step = bstream.StepNewFinal
}
out = append(out, wrapBlockForkableObject(seg[i].Object.(*ForkableBlock), step, head, lib))
}
Expand Down Expand Up @@ -215,9 +215,9 @@ func (p *Forkable) blocksFromCursor(cursor *bstream.Cursor) ([]*bstream.Preproce

// send irreversible notifications up to forkdb LIB
if seg[i].BlockNum <= p.forkDB.LIBNum() {
stepType := bstream.StepIrreversible
stepType := bstream.StepFinal
if seg[i].BlockNum > cursor.Block.Num() {
stepType = bstream.StepNewIrreversible
stepType = bstream.StepNewFinal
}
out = append(out, wrapBlockForkableObject(seg[i].Object.(*ForkableBlock), stepType, head, seg[i].AsRef()))
continue
Expand Down Expand Up @@ -360,7 +360,7 @@ func (p *Forkable) targetChainBlock(blk *bstream.Block) bstream.BlockRef {
}

func (p *Forkable) matchFilter(step bstream.StepType) bool {
return p.filterSteps&step != 0
return p.filterSteps.Matches(step)
}

func (p *Forkable) computeNewLongestChain(ppBlk *ForkableBlock) []*Block {
Expand Down Expand Up @@ -545,7 +545,7 @@ func (p *Forkable) ProcessBlock(blk *bstream.Block, obj interface{}) error {
return err
}

if err := p.processStalledSegment(stalledBlocks, ppBlk.Block); err != nil {
if err := p.processStaleSegment(stalledBlocks, ppBlk.Block); err != nil {
return err
}

Expand Down Expand Up @@ -703,7 +703,7 @@ func (p *Forkable) processInitialInclusiveIrreversibleBlock(blk *bstream.Block,
}

func (p *Forkable) processIrreversibleSegment(irreversibleSegment []*Block, headBlock bstream.BlockRef) error {
if p.matchFilter(bstream.StepIrreversible) {
if p.matchFilter(bstream.StepFinal) {
var irrGroup []*bstream.PreprocessedBlock
for _, irrBlock := range irreversibleSegment {
preprocBlock := irrBlock.Object.(*ForkableBlock)
Expand All @@ -717,7 +717,7 @@ func (p *Forkable) processIrreversibleSegment(irreversibleSegment []*Block, head
preprocBlock := irrBlock.Object.(*ForkableBlock)

objWrap := &ForkableObject{
step: bstream.StepIrreversible,
step: bstream.StepFinal,
lastLIBSent: preprocBlock.Block.AsRef(), // we are that lastLIBSent
Obj: preprocBlock.Obj,
block: preprocBlock.Block.AsRef(),
Expand All @@ -743,8 +743,8 @@ func (p *Forkable) processIrreversibleSegment(irreversibleSegment []*Block, head
return nil
}

func (p *Forkable) processStalledSegment(stalledBlocks []*Block, headBlock bstream.BlockRef) error {
if p.matchFilter(bstream.StepStalled) {
func (p *Forkable) processStaleSegment(stalledBlocks []*Block, headBlock bstream.BlockRef) error {
if p.matchFilter(bstream.StepStale) {
var stalledGroup []*bstream.PreprocessedBlock
for _, staleBlock := range stalledBlocks {
preprocBlock := staleBlock.Object.(*ForkableBlock)
Expand All @@ -758,7 +758,7 @@ func (p *Forkable) processStalledSegment(stalledBlocks []*Block, headBlock bstre
preprocBlock := staleBlock.Object.(*ForkableBlock)

objWrap := &ForkableObject{
step: bstream.StepStalled,
step: bstream.StepStale,
lastLIBSent: p.lastLIBSeen,
Obj: preprocBlock.Obj,
block: staleBlock.AsRef(),
Expand Down
Loading

0 comments on commit 6c4cb8d

Please sign in to comment.