Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

feat(prover): flag for proving unassigned proofs or not #314

Merged
merged 7 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions cmd/flags/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,20 @@ var (
Name: "taikoProverPoolL1",
Usage: "TaikoProverPoolL1 contract address",
Required: true,
Category: commonCategory,
Category: proverCategory,
}
CheckProofWindowExpiredInterval = &cli.Uint64Flag{
Name: "prover.checkProofWindowExpiredInterval",
Usage: "Interval in seconds to check for expired proof windows from other provers",
Category: commonCategory,
Category: proverCategory,
Value: 15,
}
ProveUnassignedBlocks = &cli.BoolFlag{
Name: "prover.ProveUnassignedBlocks",
Usage: "Whether you want to prove unassigned blocks, or only work on assigned proofs",
Category: proverCategory,
Value: true,
}
)

// All prover flags.
Expand All @@ -100,4 +106,5 @@ var ProverFlags = MergeFlags(CommonFlags, []cli.Flag{
Graffiti,
TaikoProverPoolL1Address,
CheckProofWindowExpiredInterval,
ProveUnassignedBlocks,
})
2 changes: 2 additions & 0 deletions prover/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Config struct {
BackOffMaxRetrys uint64
BackOffRetryInterval time.Duration
CheckProofWindowExpiredInterval time.Duration
ProveUnassignedBlocks bool
}

// NewConfigFromCliContext creates a new config instance from command line flags.
Expand Down Expand Up @@ -121,5 +122,6 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
CheckProofWindowExpiredInterval: time.Duration(
c.Uint64(flags.CheckProofWindowExpiredInterval.Name),
) * time.Second,
ProveUnassignedBlocks: c.Bool(flags.ProveUnassignedBlocks.Name),
}, nil
}
3 changes: 3 additions & 0 deletions prover/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var testFlags = []cli.Flag{
&cli.StringFlag{Name: flags.Graffiti.Name},
&cli.StringFlag{Name: flags.TaikoProverPoolL1Address.Name},
&cli.Uint64Flag{Name: flags.CheckProofWindowExpiredInterval.Name},
&cli.BoolFlag{Name: flags.ProveUnassignedBlocks.Name},
}

func (s *ProverTestSuite) TestNewConfigFromCliContext_OracleProver() {
Expand Down Expand Up @@ -62,6 +63,7 @@ func (s *ProverTestSuite) TestNewConfigFromCliContext_OracleProver() {
)
s.Equal("", c.Graffiti)
s.Equal(30*time.Second, c.CheckProofWindowExpiredInterval)
s.Equal(true, c.ProveUnassignedBlocks)
s.Nil(new(Prover).InitFromCli(context.Background(), ctx))

return err
Expand All @@ -83,6 +85,7 @@ func (s *ProverTestSuite) TestNewConfigFromCliContext_OracleProver() {
"-" + flags.OracleProverPrivateKey.Name, os.Getenv("L1_PROVER_PRIVATE_KEY"),
"-" + flags.Graffiti.Name, "",
"-" + flags.CheckProofWindowExpiredInterval.Name, "30",
"-" + flags.ProveUnassignedBlocks.Name, "true",
}))
}

Expand Down
56 changes: 50 additions & 6 deletions prover/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,16 +508,44 @@ func (p *Prover) onBlockProposed(
}

if !skipProofWindowExpiredCheck {
proofWindowExpired := uint64(time.Now().Unix()) > block.ProposedAt+block.ProofWindow
proofWindowExpiresAt := block.ProposedAt + block.ProofWindow
proofWindowExpired := uint64(time.Now().Unix()) > proofWindowExpiresAt
// zero address means anyone can prove, proofWindowExpired means anyone can prove even if not zero address
if block.AssignedProver != p.proverAddress && block.AssignedProver != zeroAddress && !proofWindowExpired {
log.Info("Proposed block not proveable", "blockID", event.BlockId, "prover", block.AssignedProver.Hex())
log.Info("Proposed block not proveable",
"blockID",
event.BlockId,
"prover",
block.AssignedProver.Hex(),
"proofWindowExpiresAt",
proofWindowExpiresAt,
)

// if we cant prove it now, but config is set to wait and try to prove
// expired proofs
if p.cfg.ProveUnassignedBlocks {
log.Info("Adding proposed block to wait for proof window expiration",
"blockID",
event.BlockId,
"prover",
block.AssignedProver.Hex(),
"proofWindowExpiresAt",
proofWindowExpiresAt,
)
p.currentBlocksWaitingForProofWindowMutex.Lock()
p.currentBlocksWaitingForProofWindow[event.Meta.Id] = event.Raw.BlockNumber
p.currentBlocksWaitingForProofWindowMutex.Unlock()
}

// if we cant prove it
p.currentBlocksWaitingForProofWindowMutex.Lock()
p.currentBlocksWaitingForProofWindow[event.Meta.Id] = event.Raw.BlockNumber
p.currentBlocksWaitingForProofWindowMutex.Unlock()
return nil
}

// if set not to prove unassigned blocks, this block is still not provable
// by us even though its open proving.
if block.AssignedProver == zeroAddress && !p.cfg.ProveUnassignedBlocks {
log.Info("Skipping proposed open proving block, not assigned to us",
"blockID", event.BlockId,
)
return nil
}

Expand Down Expand Up @@ -834,6 +862,12 @@ func (p *Prover) checkProofWindowExpired(ctx context.Context, l1Height, blockId
}

if forkChoice.Prover == zeroAddress {
log.Info("proof window for proof not assigned to us expired, requesting proof",
"blockID",
blockId,
"l1Height",
l1Height,
)
// we can generate the proof, no proof came in by proof window expiring
p.proveNotify <- big.NewInt(int64(l1Height))
} else {
Expand All @@ -847,6 +881,16 @@ func (p *Prover) checkProofWindowExpired(ctx context.Context, l1Height, blockId
// if the hashes dont match, we can generate proof even though
// a proof came in before proofwindow expired.
if block.Hash() != forkChoice.BlockHash {
log.Info("invalid proof detected while watching for proof window expiration, requesting proof",
"blockID",
blockId,
"l1Height",
l1Height,
"expectedBlockHash",
block.Hash(),
"forkChoiceBlockHash",
common.Bytes2Hex(forkChoice.BlockHash[:]),
)
// we can generate the proof, the proof is incorrect since blockHash does not match
// the correct one but parentHash/gasUsed are correct.
p.proveNotify <- new(big.Int).SetUint64(l1Height)
Expand Down
1 change: 1 addition & 0 deletions prover/prover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func (s *ProverTestSuite) SetupTest() {
Dummy: true,
MaxConcurrentProvingJobs: 1,
CheckProofWindowExpiredInterval: 5 * time.Second,
ProveUnassignedBlocks: true,
})))
s.p = p
s.cancel = cancel
Expand Down