Skip to content

Commit

Permalink
feat: network-v2 compatibility (#244)
Browse files Browse the repository at this point in the history
* Compiles without network-v2 feature

* Compiles and swapped out everything

* add

* add

* feat: update network v2

* add

* add

* add

* add

* add

* fix

* configure port

* add

* use hosted

* fix: reserved

* fix

* add

* feat: deployed

* added

* add

* push fixes

* feat: re-starting proposer

* wip

* fix

* only submitted agg proof with greatest distance

* fix

* fix

* fix"

* add

* add

* add

* add

* fix

* add

---------

Co-authored-by: ratankaliani <[email protected]>
  • Loading branch information
puma314 and ratankaliani authored Dec 10, 2024
1 parent a98ce28 commit c48afb3
Show file tree
Hide file tree
Showing 15 changed files with 1,058 additions and 627 deletions.
1,193 changes: 733 additions & 460 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,11 @@ op-alloy-network = { version = "0.6.8", default-features = false }
# sp1
sp1-lib = { version = "3.0.0", features = ["verify"] }
sp1-zkvm = { version = "3.0.0", features = ["verify"] }
# Note: This rev is on a branch which includes skipping deferred verification + SP1 mock groth16 bytes fix + executor opts. Once 4.0.0 is released, update this.
# ratan/op-succinct-sp1
sp1-sdk = { git = "https://github.com/succinctlabs/sp1.git", rev = "884948a30c9b125950b9ddf7a344fb69548cd9df" }
# Note: This rev includes the SP1 mock groth16 bytes fix, skipping deferred verification, executor opts and network-v2 changes.
# ratan/v3.0.0-w-network-v2 branch includes the network-v2 changes from `19ae3e1`.
sp1-sdk = { git = "https://github.com/succinctlabs/sp1.git", rev = "447fda5f759908bbc3091979bd933ee9d126873b", features = [
"network-v2",
] }
sp1-build = { version = "3.0.0" }

[profile.release-client-lto]
Expand Down
1 change: 1 addition & 0 deletions configs/808813/rollup.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"ecotone_time": 0,
"fjord_time": 0,
"granite_time": 1725984001,
"holocene_time": 1732633200,
"batch_inbox_address": "0x734dde12fd466c14a85de838788efe6f1993c84c",
"deposit_contract_address": "0xbaaf3bafdbd660380938b27d21c31bb7d072a799",
"l1_system_config_address": "0x3974436fa4bb4deb5a04ace51a704b10ff5a1f25",
Expand Down
15 changes: 15 additions & 0 deletions contracts/opsuccinctl2ooconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"challenger": "0x0000000000000000000000000000000000000000",
"finalizationPeriod": 0,
"l2BlockTime": 2,
"owner": "0xDEd0000E32f8F40414d3ab3a830f735a3553E18e",
"proposer": "0xDEd0000E32f8F40414d3ab3a830f735a3553E18e",
"rollupConfigHash": "0x0d7101e2acc7eae1fb42cfce5c604d14da561726e4e01b509315e5a9f97a9816",
"startingBlockNumber": 5591859,
"startingOutputRoot": "0xd2c903c40513a87898b2830196d53e0bedabe5dfba09c002b9cc39cb0ba5fe46",
"startingTimestamp": 1733536206,
"submissionInterval": 1200,
"verifier": "0x397A5f7f3dBd538f23DE225B51f532c34448dA9B",
"aggregationVkey": "0x00ea4171dbd0027768055bee7f6d64e17e9cec99b29aad5d18e5d804b967775b",
"rangeVkeyCommitment": "0x51decb4a49105f2a1403423f560bc55d6d02e5eb57f21d0c5bd6a661555a8e53"
}
9 changes: 9 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ deploy-oracle env_file=".env":
# cd into contracts directory
cd contracts

# forge install
forge install

# Run the forge deployment script
forge script script/OPSuccinctDeployer.s.sol:OPSuccinctDeployer \
Expand All @@ -173,6 +176,9 @@ upgrade-oracle env_file=".env":
# cd into contracts directory
cd contracts

# forge install
forge install

# Run the forge upgrade script
if [ "${EXECUTE_UPGRADE_CALL:-true}" = "false" ]; then
Expand Down Expand Up @@ -203,6 +209,9 @@ update-parameters env_file=".env":
# cd into contracts directory
cd contracts

# forge install
forge install

# Run the forge upgrade script
if [ "${EXECUTE_UPGRADE_CALL:-true}" = "false" ]; then
Expand Down
2 changes: 1 addition & 1 deletion proposer/op/bindings/opsuccinctl2outputoracle.go

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions proposer/op/proposer/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package db

import (
"context"
"encoding/hex"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -117,10 +118,13 @@ func (db *ProofDB) UpdateProofStatus(id int, proofStatus proofrequest.Status) er
}

// SetProverRequestID sets the prover request ID for a proof request in the database.
func (db *ProofDB) SetProverRequestID(id int, proverRequestID string) error {
func (db *ProofDB) SetProverRequestID(id int, proverRequestID []byte) error {
// Convert the []byte to a hex string.
proverRequestIDHex := hex.EncodeToString(proverRequestID)

_, err := db.writeClient.ProofRequest.Update().
Where(proofrequest.ID(id)).
SetProverRequestID(proverRequestID).
SetProverRequestID(proverRequestIDHex).
SetProofRequestTime(uint64(time.Now().Unix())).
SetLastUpdatedTime(uint64(time.Now().Unix())).
Save(context.Background())
Expand Down Expand Up @@ -437,7 +441,8 @@ func (db *ProofDB) GetMaxContiguousSpanProofRange(start uint64) (uint64, error)
currentBlock = span.EndBlock
}

return max(start, currentBlock), nil
// The current block is at minimum the start block, and at maximum the end block of the last span proof.
return currentBlock, nil
}

// GetConsecutiveSpanProofs returns the span proofs that cover the range [start, end].
Expand Down
47 changes: 37 additions & 10 deletions proposer/op/proposer/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"math/big"
_ "net/http/pprof"
"sort"
"sync"
"time"

Expand Down Expand Up @@ -251,6 +252,12 @@ func (l *L2OutputSubmitter) GetProposerMetrics(ctx context.Context) (opsuccinctm
return opsuccinctmetrics.ProposerMetrics{}, fmt.Errorf("failed to get max contiguous span proof range: %w", err)
}

// This fetches the next block number, which is the currentBlock + submissionInterval.
minBlockToProveToAgg, err := l.l2ooContract.NextBlockNumber(&bind.CallOpts{Context: ctx})
if err != nil {
return opsuccinctmetrics.ProposerMetrics{}, fmt.Errorf("failed to get next L2OO output: %w", err)
}

numProving, err := l.db.GetNumberOfRequestsWithStatuses(proofrequest.StatusPROVING)
if err != nil {
return opsuccinctmetrics.ProposerMetrics{}, fmt.Errorf("failed to get number of proofs proving: %w", err)
Expand All @@ -271,6 +278,7 @@ func (l *L2OutputSubmitter) GetProposerMetrics(ctx context.Context) (opsuccinctm
L2FinalizedBlock: l2FinalizedBlock,
LatestContractL2Block: latestContractL2Block.Uint64(),
HighestProvenContiguousL2Block: highestProvenContiguousL2Block,
MinBlockToProveToAgg: minBlockToProveToAgg.Uint64(),
NumProving: uint64(numProving),
NumWitnessgen: uint64(numWitnessgen),
NumUnrequested: uint64(numUnrequested),
Expand Down Expand Up @@ -312,8 +320,8 @@ func (l *L2OutputSubmitter) SendSlackNotification(proposerMetrics opsuccinctmetr

message := fmt.Sprintf("*Chain %d Proposer Metrics*:\n"+
"Contract is %d minutes behind L2 Finalized\n"+
"| L2 Unsafe | L2 Finalized | Contract L2 | Proven L2 |\n"+
"| %-9d | %-12d | %-11d | %-9d |\n"+
"| L2 Unsafe | L2 Finalized | Contract L2 | Proven L2 | Min to Agg |\n"+
"| %-9d | %-12d | %-11d | %-9d | %-9d |\n"+
"| Proving | Witness Gen | Unrequested |\n"+
"| %-9d | %-11d | %-11d |",
l.Cfg.L2ChainID,
Expand All @@ -322,6 +330,7 @@ func (l *L2OutputSubmitter) SendSlackNotification(proposerMetrics opsuccinctmetr
proposerMetrics.L2FinalizedBlock,
proposerMetrics.LatestContractL2Block,
proposerMetrics.HighestProvenContiguousL2Block,
proposerMetrics.MinBlockToProveToAgg,
proposerMetrics.NumProving,
proposerMetrics.NumWitnessgen,
proposerMetrics.NumUnrequested)
Expand Down Expand Up @@ -354,12 +363,20 @@ func (l *L2OutputSubmitter) SubmitAggProofs(ctx context.Context) error {
return nil
}

for _, aggProof := range completedAggProofs {
output, err := l.FetchOutput(ctx, aggProof.EndBlock)
if err != nil {
return fmt.Errorf("failed to fetch output at block %d: %w", aggProof.EndBlock, err)
}
l.proposeOutput(ctx, output, aggProof.Proof, aggProof.L1BlockNumber)
// Select the agg proof with the highest L2 block number.
sort.Slice(completedAggProofs, func(i, j int) bool {
return completedAggProofs[i].EndBlock > completedAggProofs[j].EndBlock
})

// Submit the agg proof with the highest L2 block number.
aggProof := completedAggProofs[0]
output, err := l.FetchOutput(ctx, aggProof.EndBlock)
if err != nil {
return fmt.Errorf("failed to fetch output at block %d: %w", aggProof.EndBlock, err)
}
err = l.proposeOutput(ctx, output, aggProof.Proof, aggProof.L1BlockNumber)
if err != nil {
return fmt.Errorf("failed to propose output: %w", err)
}

return nil
Expand Down Expand Up @@ -675,20 +692,30 @@ func (l *L2OutputSubmitter) loopL2OO(ctx context.Context) {
}
}

func (l *L2OutputSubmitter) proposeOutput(ctx context.Context, output *eth.OutputResponse, proof []byte, l1BlockNum uint64) {
func (l *L2OutputSubmitter) proposeOutput(ctx context.Context, output *eth.OutputResponse, proof []byte, l1BlockNum uint64) error {
cCtx, cancel := context.WithTimeout(ctx, 10*time.Minute)
defer cancel()

// Get the current nextBlockNumber from the L2OO contract.
nextBlockNumber, err := l.l2ooContract.NextBlockNumber(&bind.CallOpts{Context: cCtx})
if err != nil {
l.Log.Error("Failed to get nextBlockNumber", "err", err)
return err
}

if err := l.sendTransaction(cCtx, output, proof, l1BlockNum); err != nil {
l.Log.Error("Failed to send proposal transaction",
"err", err,
"expected_next_blocknum", nextBlockNumber.Uint64(),
"l2blocknum", output.BlockRef.Number,
"l1blocknum", l1BlockNum,
"l1head", output.Status.HeadL1.Number,
"proof", proof)
return
return err
}
l.Log.Info("AGG proof submitted on-chain", "end", output.BlockRef.Number)
l.Metr.RecordL2BlocksProposed(output.BlockRef)
return nil
}

// checkpointBlockHash gets the current L1 head, and then sends a transaction to checkpoint the blockhash on
Expand Down
140 changes: 74 additions & 66 deletions proposer/op/proposer/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ type OPSuccinctMetrics struct {
L2FinalizedBlock prometheus.Gauge
LatestContractL2Block prometheus.Gauge
HighestProvenContiguousL2Block prometheus.Gauge
MinBlockToProveToAgg prometheus.Gauge

ErrorCount *prometheus.CounterVec
ProveFailures *prometheus.CounterVec
ErrorCount *prometheus.CounterVec
ProveFailures *prometheus.CounterVec
WitnessGenFailures *prometheus.CounterVec
}

Expand All @@ -66,70 +67,75 @@ func NewMetrics(procName string) *OPSuccinctMetrics {

return &OPSuccinctMetrics{
ns: ns,
registry: registry,
factory: factory,

RefMetrics: opmetrics.MakeRefMetrics(ns, factory),
TxMetrics: txmetrics.MakeTxMetrics(ns, factory),
RPCMetrics: opmetrics.MakeRPCMetrics(ns, factory),

info: *factory.NewGaugeVec(prometheus.GaugeOpts{
Namespace: ns,
Name: "info",
Help: "Pseudo-metric tracking version and config info",
}, []string{
"version",
}),
up: factory.NewGauge(prometheus.GaugeOpts{
Namespace: ns,
Name: "up",
Help: "1 if the op-proposer has finished starting up",
}),
NumProving: factory.NewGauge(prometheus.GaugeOpts{
Namespace: ns,
Name: "num_proving",
Help: "Number of proofs currently being proven",
}),
NumWitnessGen: factory.NewGauge(prometheus.GaugeOpts{
Namespace: ns,
Name: "num_witness_gen",
Help: "Number of witnesses currently being generated",
}),
NumUnrequested: factory.NewGauge(prometheus.GaugeOpts{
Namespace: ns,
Name: "num_unrequested",
Help: "Number of unrequested proofs",
}),
L2FinalizedBlock: factory.NewGauge(prometheus.GaugeOpts{
Namespace: ns,
Name: "l2_finalized_block",
Help: "Latest finalized L2 block number",
}),
LatestContractL2Block: factory.NewGauge(prometheus.GaugeOpts{
Namespace: ns,
Name: "latest_contract_l2_block",
Help: "Latest L2 block number on the L2OO contract",
}),
HighestProvenContiguousL2Block: factory.NewGauge(prometheus.GaugeOpts{
Namespace: ns,
Name: "highest_proven_contiguous_l2_block",
Help: "Highest proven L2 block contiguous with contract's latest block",
}),
ErrorCount: factory.NewCounterVec(prometheus.CounterOpts{
Namespace: ns,
Name: "error_count",
Help: "Number of errors encountered",
}, []string{"type"}),
ProveFailures: factory.NewCounterVec(prometheus.CounterOpts{
Namespace: ns,
Name: "prove_failures",
Help: "Number of prove failures by type",
}, []string{"reason"}),
WitnessGenFailures: factory.NewCounterVec(prometheus.CounterOpts{
Namespace: ns,
Name: "witness_gen_failures",
Help: "Number of witness generation failures by type",
}, []string{"reason"}),
registry: registry,
factory: factory,

RefMetrics: opmetrics.MakeRefMetrics(ns, factory),
TxMetrics: txmetrics.MakeTxMetrics(ns, factory),
RPCMetrics: opmetrics.MakeRPCMetrics(ns, factory),

info: *factory.NewGaugeVec(prometheus.GaugeOpts{
Namespace: ns,
Name: "info",
Help: "Pseudo-metric tracking version and config info",
}, []string{
"version",
}),
up: factory.NewGauge(prometheus.GaugeOpts{
Namespace: ns,
Name: "up",
Help: "1 if the op-proposer has finished starting up",
}),
NumProving: factory.NewGauge(prometheus.GaugeOpts{
Namespace: ns,
Name: "num_proving",
Help: "Number of proofs currently being proven",
}),
NumWitnessGen: factory.NewGauge(prometheus.GaugeOpts{
Namespace: ns,
Name: "num_witness_gen",
Help: "Number of witnesses currently being generated",
}),
NumUnrequested: factory.NewGauge(prometheus.GaugeOpts{
Namespace: ns,
Name: "num_unrequested",
Help: "Number of unrequested proofs",
}),
L2FinalizedBlock: factory.NewGauge(prometheus.GaugeOpts{
Namespace: ns,
Name: "l2_finalized_block",
Help: "Latest finalized L2 block number",
}),
LatestContractL2Block: factory.NewGauge(prometheus.GaugeOpts{
Namespace: ns,
Name: "latest_contract_l2_block",
Help: "Latest L2 block number on the L2OO contract",
}),
HighestProvenContiguousL2Block: factory.NewGauge(prometheus.GaugeOpts{
Namespace: ns,
Name: "highest_proven_contiguous_l2_block",
Help: "Highest proven L2 block contiguous with contract's latest block",
}),
MinBlockToProveToAgg: factory.NewGauge(prometheus.GaugeOpts{
Namespace: ns,
Name: "min_block_to_prove_to_agg",
Help: "Minimum L2 block number to prove to generate an AGG proof",
}),
ErrorCount: factory.NewCounterVec(prometheus.CounterOpts{
Namespace: ns,
Name: "error_count",
Help: "Number of errors encountered",
}, []string{"type"}),
ProveFailures: factory.NewCounterVec(prometheus.CounterOpts{
Namespace: ns,
Name: "prove_failures",
Help: "Number of prove failures by type",
}, []string{"reason"}),
WitnessGenFailures: factory.NewCounterVec(prometheus.CounterOpts{
Namespace: ns,
Name: "witness_gen_failures",
Help: "Number of witness generation failures by type",
}, []string{"reason"}),
}
}

Expand Down Expand Up @@ -189,13 +195,15 @@ func (m *OPSuccinctMetrics) RecordProposerStatus(metrics ProposerMetrics) {
m.L2FinalizedBlock.Set(float64(metrics.L2FinalizedBlock))
m.LatestContractL2Block.Set(float64(metrics.LatestContractL2Block))
m.HighestProvenContiguousL2Block.Set(float64(metrics.HighestProvenContiguousL2Block))
m.MinBlockToProveToAgg.Set(float64(metrics.MinBlockToProveToAgg))
}

type ProposerMetrics struct {
L2UnsafeHeadBlock uint64
L2FinalizedBlock uint64
LatestContractL2Block uint64
HighestProvenContiguousL2Block uint64
MinBlockToProveToAgg uint64
NumProving uint64
NumWitnessgen uint64
NumUnrequested uint64
Expand Down
Loading

0 comments on commit c48afb3

Please sign in to comment.