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

feat(prover): cancel proof if it becomes verified #207

Merged
merged 45 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
0347a95
cancel proof if it becomes verified, also check before submitting aft…
cyberhorsey May 3, 2023
d870565
delete proof when submitting
cyberhorsey May 3, 2023
37b111f
log
cyberhorsey May 3, 2023
1e0e7ca
logs
cyberhorsey May 3, 2023
01171d5
test
cyberhorsey May 3, 2023
4172463
lint
cyberhorsey May 3, 2023
a1ffa4f
return
cyberhorsey May 3, 2023
956f12b
delete
cyberhorsey May 3, 2023
8836dde
use main
cyberhorsey May 3, 2023
4c39417
rm ref
cyberhorsey May 3, 2023
ff5d8cd
Merge branch 'main' into abandon_proof
cyberhorsey May 3, 2023
8db8e24
Typo
cyberhorsey May 3, 2023
ba074f2
Merge branch 'abandon_proof' of github.com:taikochain/taiko-client in…
cyberhorsey May 3, 2023
99ecca3
Merge branch 'main' into abandon_proof
cyberhorsey May 3, 2023
d2c5714
Merge branch 'main' into abandon_proof
davidtaikocha May 3, 2023
616fef3
add blockProven to prover, cancel proof if so
cyberhorsey May 3, 2023
ed339b2
Merge branch 'abandon_proof' of github.com:taikochain/taiko-client in…
cyberhorsey May 3, 2023
18b614e
metric
cyberhorsey May 3, 2023
75409e3
oracle proof producer can now use the new getOracleProver to make sur…
cyberhorsey May 3, 2023
6b997ed
.
cyberhorsey May 3, 2023
fbba664
.
cyberhorsey May 3, 2023
23b46d9
make sure parentgas used and hash are as expected
cyberhorsey May 3, 2023
d1a9214
dont need to check parent on block verified
cyberhorsey May 3, 2023
46168f8
unnecessary guard
cyberhorsey May 3, 2023
6aa9766
cancel proof doesnt return err
cyberhorsey May 3, 2023
5674d7d
defer
cyberhorsey May 3, 2023
21b167e
lint
cyberhorsey May 3, 2023
8f63778
line length
cyberhorsey May 3, 2023
1470fb2
.
cyberhorsey May 3, 2023
dfbe791
mutex
cyberhorsey May 3, 2023
30d7235
.
cyberhorsey May 3, 2023
29bc0a0
bindings, no gasUsed
cyberhorsey May 3, 2023
8ad77b8
run tests on ref
cyberhorsey May 3, 2023
fa156e1
cancelproof stub/dummys
cyberhorsey May 4, 2023
566c48e
lint
cyberhorsey May 4, 2023
81f415a
logs
cyberhorsey May 4, 2023
2c710bf
Merge branch 'main' into abandon_proof
davidtaikocha May 4, 2023
1721da5
add oracleproverprivatekey flag
cyberhorsey May 4, 2023
a9526c1
merge
cyberhorsey May 4, 2023
1081889
privkey
cyberhorsey May 4, 2023
a267d13
oracleproverkey config
cyberhorsey May 4, 2023
759e493
test for oracleprover without privkey
cyberhorsey May 4, 2023
ad6f6ce
tests
cyberhorsey May 4, 2023
2f82b96
Typo
cyberhorsey May 4, 2023
33ea859
ref
cyberhorsey May 5, 2023
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
14 changes: 14 additions & 0 deletions prover/proof_submitter/valid_proof_submitter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,20 @@ func (s *ProofSubmitterTestSuite) TestValidSubmitProofs() {
}
}

func (s *ProofSubmitterTestSuite) TestValidProofSubmitterRequestProofCancelled() {
ctx, cancel := context.WithCancel(context.Background())
go func() {
time.AfterFunc(2*time.Second, func() {
cancel()
})
}()

s.ErrorContains(
s.validProofSubmitter.RequestProof(
ctx, &bindings.TaikoL1ClientBlockProposed{Id: common.Big256}), "context canceled",
)
}

func TestProofSubmitterTestSuite(t *testing.T) {
suite.Run(t, new(ProofSubmitterTestSuite))
}
40 changes: 39 additions & 1 deletion prover/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ type Prover struct {
submitProofConcurrencyGuard chan struct{}
submitProofTxMutex *sync.Mutex

currentBlocksBeingProven map[uint64]context.CancelFunc

ctx context.Context
wg sync.WaitGroup
}
Expand All @@ -79,6 +81,7 @@ func (p *Prover) InitFromCli(ctx context.Context, c *cli.Context) error {
func InitFromConfig(ctx context.Context, p *Prover, cfg *Config) (err error) {
p.cfg = cfg
p.ctx = ctx
p.currentBlocksBeingProven = make(map[uint64]context.CancelFunc)

// Clients
if p.rpc, err = rpc.NewClient(p.ctx, &rpc.ClientConfig{
Expand Down Expand Up @@ -287,6 +290,9 @@ func (p *Prover) onBlockProposed(
return nil
}

ctx, cancel := context.WithCancel(ctx)
p.currentBlocksBeingProven[event.Id.Uint64()] = cancel

return p.validProofSubmitter.RequestProof(ctx, event)
}

Expand All @@ -297,6 +303,7 @@ func (p *Prover) onBlockProposed(

go func() {
if err := handleBlockProposedEvent(); err != nil {
delete(p.currentBlocksBeingProven, event.Id.Uint64())
log.Error("Handle new BlockProposed event error", "error", err)
}
}()
Expand All @@ -308,7 +315,29 @@ func (p *Prover) onBlockProposed(
func (p *Prover) submitProofOp(ctx context.Context, proofWithHeader *proofProducer.ProofWithHeader, isValidProof bool) {
p.submitProofConcurrencyGuard <- struct{}{}
go func() {
defer func() { <-p.submitProofConcurrencyGuard }()
defer func() {
<-p.submitProofConcurrencyGuard
delete(p.currentBlocksBeingProven, proofWithHeader.Meta.Id)
}()

// check if block has been verified since we started generating the proof.
// if it has been, transaction will revert, so we avoid gas fees even though
// we generated a proof we won't use.
isVerified, err := p.isBlockVerified(new(big.Int).SetUint64(proofWithHeader.Meta.Id))
davidtaikocha marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
log.Error("is block verified error", "isValidProof", isValidProof, "blockID", proofWithHeader.Meta.Id, "error", err)
return
}

if isVerified {
log.Info("📋 Block has been verified, not submitting proof",
"isValidProof",
isValidProof,
"blockID",
proofWithHeader.Meta.Id,
)
return
}

if err := p.validProofSubmitter.SubmitProof(p.ctx, proofWithHeader); err != nil {
log.Error("Submit proof error", "isValidProof", isValidProof, "error", err)
Expand All @@ -328,6 +357,15 @@ func (p *Prover) onBlockVerified(ctx context.Context, event *bindings.TaikoL1Cli
}

log.Info("New verified valid block", "blockID", event.Id, "hash", common.BytesToHash(event.BlockHash[:]))

// cancel any proofs being generated for this block
if cancel, ok := p.currentBlocksBeingProven[event.Id.Uint64()]; ok {
log.Info("Cancelling proof for ", "blockID", event.Id, "hash", common.BytesToHash(event.BlockHash[:]))
cancel()
delete(p.currentBlocksBeingProven, event.Id.Uint64())
log.Info("Cancelled proof for ", "blockID", event.Id, "hash", common.BytesToHash(event.BlockHash[:]))
}

return nil
}

Expand Down