From 20c14235b087e4624427879aa587a1599690dbbb Mon Sep 17 00:00:00 2001 From: David Date: Fri, 5 May 2023 23:38:11 +0800 Subject: [PATCH] feat(prover): improve oracle proof submission delay (#212) --- proposer/proposer.go | 2 +- prover/proof_producer/oracle_proof_producer.go | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/proposer/proposer.go b/proposer/proposer.go index 81b1dd1cd..03027969b 100644 --- a/proposer/proposer.go +++ b/proposer/proposer.go @@ -343,7 +343,7 @@ func (p *Proposer) checkTaikoTokenBalance() error { } if balance.Cmp(new(big.Int).SetUint64(fee)) == -1 { - return fmt.Errorf("proposer does not have enough tko balance to propose") + return fmt.Errorf("proposer does not have enough tko balance to propose, balance: %d, fee: %d", balance, fee) } return nil diff --git a/prover/proof_producer/oracle_proof_producer.go b/prover/proof_producer/oracle_proof_producer.go index 5a92d8bdc..c1642df02 100644 --- a/prover/proof_producer/oracle_proof_producer.go +++ b/prover/proof_producer/oracle_proof_producer.go @@ -119,7 +119,18 @@ func (p *OracleProducer) RequestProof( return fmt.Errorf("failed to sign evidence: %w", err) } - time.AfterFunc(p.proofTimeTarget, func() { + var ( + delay time.Duration = 0 + now = time.Now() + blockTime = time.Unix(int64(block.Time()), 0) + ) + if now.Before(blockTime.Add(p.proofTimeTarget)) { + delay = blockTime.Add(p.proofTimeTarget).Sub(now) + } + + log.Info("Oracle proof submission delay", "delay", delay) + + time.AfterFunc(delay, func() { resultCh <- &ProofWithHeader{ BlockID: blockID, Header: header,