Skip to content

Commit

Permalink
[P-TX] use Banff block time for TX
Browse files Browse the repository at this point in the history
  • Loading branch information
peak3d committed Mar 22, 2023
1 parent 2bc2772 commit 7fac00f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
3 changes: 3 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

go build cmds/magelland/magelland.go
18 changes: 10 additions & 8 deletions services/indexes/pvm/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,12 @@ func (w *Writer) indexBlock(ctx services.ConsumerCtx, blockBytes []byte) error {
ctxTime := ctx.Time()
pvmProposer := models.NewBlockProposal(proposerBlock, &ctxTime)

adjustCtxTime := func(tm uint64) {
ctxTime := time.Unix(int64(tm), 0)
ctx.SetTime(ctxTime)
pvmProposer.TimeStamp = &ctxTime
}

errs := wrappers.Errs{}
switch blk := blk.(type) {
case *blocks.ApricotProposalBlock:
Expand All @@ -387,20 +393,16 @@ func (w *Writer) indexBlock(ctx services.ConsumerCtx, blockBytes []byte) error {
case *blocks.ApricotCommitBlock:
errs.Add(w.indexCommonBlock(ctx, blkID, models.BlockTypeCommit, blk.CommonBlock, pvmProposer, innerBlockBytes))
case *blocks.BanffProposalBlock:
ctxTime = time.Unix(int64(blk.Time), 0)
pvmProposer.TimeStamp = &ctxTime
adjustCtxTime(blk.Time)
errs.Add(w.indexCommonBlock(ctx, blkID, models.BlockTypeStandard, blk.CommonBlock, pvmProposer, innerBlockBytes))
case *blocks.BanffStandardBlock:
ctxTime = time.Unix(int64(blk.Time), 0)
pvmProposer.TimeStamp = &ctxTime
adjustCtxTime(blk.Time)
errs.Add(w.indexCommonBlock(ctx, blkID, models.BlockTypeStandard, blk.CommonBlock, pvmProposer, innerBlockBytes))
case *blocks.BanffAbortBlock:
ctxTime = time.Unix(int64(blk.Time), 0)
pvmProposer.TimeStamp = &ctxTime
adjustCtxTime(blk.Time)
errs.Add(w.indexCommonBlock(ctx, blkID, models.BlockTypeAbort, blk.CommonBlock, pvmProposer, innerBlockBytes))
case *blocks.BanffCommitBlock:
ctxTime = time.Unix(int64(blk.Time), 0)
pvmProposer.TimeStamp = &ctxTime
adjustCtxTime(blk.Time)
errs.Add(w.indexCommonBlock(ctx, blkID, models.BlockTypeCommit, blk.CommonBlock, pvmProposer, innerBlockBytes))
default:
return fmt.Errorf("unknown type %T", blk)
Expand Down
1 change: 1 addition & 0 deletions services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ func (ic *ConsumerCtx) DB() dbr.SessionRunner { return ic.db }
func (ic *ConsumerCtx) Ctx() context.Context { return ic.ctx }
func (ic *ConsumerCtx) Persist() db.Persist { return ic.persist }
func (ic *ConsumerCtx) ChainID() string { return ic.chainID }
func (ic *ConsumerCtx) SetTime(tm time.Time) { ic.time = tm }

0 comments on commit 7fac00f

Please sign in to comment.