Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bring changes from v0.0.2 rc2 #1644

Merged
merged 10 commits into from
Feb 7, 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
7 changes: 7 additions & 0 deletions aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ func (a *Aggregator) Channel(stream pb.AggregatorService_ChannelServer) error {
)
log.Debug("Establishing stream connection with prover")

// Check if prover supports the required Fork ID
if !prover.SupportsForkID(a.cfg.ForkId) {
log.Warn("Prover does not support required fork ID.")
return errors.New("prover does not support required fork ID")
}

for {
select {
case <-a.ctx.Done():
Expand Down Expand Up @@ -898,6 +904,7 @@ func (a *Aggregator) buildInputProver(ctx context.Context, batchToVerify *state.
OldAccInputHash: previousBatch.AccInputHash.Bytes(),
OldBatchNum: previousBatch.BatchNumber,
ChainId: a.cfg.ChainID,
ForkId: a.cfg.ForkId,
BatchL2Data: batchToVerify.BatchL2Data,
GlobalExitRoot: batchToVerify.GlobalExitRoot.Bytes(),
EthTimestamp: uint64(batchToVerify.Timestamp.Unix()),
Expand Down
3 changes: 3 additions & 0 deletions aggregator/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ type Config struct {
// ChainID is the L2 ChainID provided by the Network Config
ChainID uint64

// ForkID is the L2 ForkID provided by the Network Config
ForkId uint64

// SenderAddress defines which private key the eth tx manager needs to use
// to sign the L1 txs
SenderAddress string `mapstructure:"SenderAddress"`
Expand Down
430 changes: 228 additions & 202 deletions aggregator/pb/aggregator.pb.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions aggregator/pb/aggregator_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 38 additions & 24 deletions aggregator/prover/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/0xPolygonHermez/zkevm-node/aggregator/metrics"
"github.com/0xPolygonHermez/zkevm-node/aggregator/pb"
"github.com/0xPolygonHermez/zkevm-node/config/types"
"github.com/0xPolygonHermez/zkevm-node/log"
)

var (
Expand Down Expand Up @@ -84,7 +85,20 @@ func (p *Prover) IsIdle() (bool, error) {
if err != nil {
return false, err
}
return status.Status == pb.GetStatusResponse_IDLE, nil
return status.Status == pb.GetStatusResponse_STATUS_IDLE, nil
}

// SupportsForkID returns true if the prover supports the given fork id.
func (p *Prover) SupportsForkID(forkID uint64) bool {
status, err := p.Status()
if err != nil {
log.Warnf("Error asking status for prover ID %s: %w", p.ID(), err)
return false
}

log.Debugf("Prover %s supports fork ID %d", p.ID(), status.ForkId)

return status.ForkId == forkID
}

// BatchProof instructs the prover to generate a batch proof for the provided
Expand All @@ -104,13 +118,13 @@ func (p *Prover) BatchProof(input *pb.InputProver) (*string, error) {

if msg, ok := res.Response.(*pb.ProverMessage_GenBatchProofResponse); ok {
switch msg.GenBatchProofResponse.Result {
case pb.Result_UNSPECIFIED:
case pb.Result_RESULT_UNSPECIFIED:
return nil, fmt.Errorf("Failed to generate proof %s, %w, input %v", msg.GenBatchProofResponse.String(), ErrUnspecified, input)
case pb.Result_OK:
case pb.Result_RESULT_OK:
return &msg.GenBatchProofResponse.Id, nil
case pb.Result_ERROR:
case pb.Result_RESULT_ERROR:
return nil, fmt.Errorf("Failed to generate proof %s, %w, input %v", msg.GenBatchProofResponse.String(), ErrBadRequest, input)
case pb.Result_INTERNAL_ERROR:
case pb.Result_RESULT_INTERNAL_ERROR:
return nil, fmt.Errorf("Failed to generate proof %s, %w, input %v", msg.GenBatchProofResponse.String(), ErrProverInternalError, input)
default:
return nil, fmt.Errorf("Failed to generate proof %s, %w,input %v", msg.GenBatchProofResponse.String(), ErrUnknown, input)
Expand Down Expand Up @@ -140,15 +154,15 @@ func (p *Prover) AggregatedProof(inputProof1, inputProof2 string) (*string, erro

if msg, ok := res.Response.(*pb.ProverMessage_GenAggregatedProofResponse); ok {
switch msg.GenAggregatedProofResponse.Result {
case pb.Result_UNSPECIFIED:
case pb.Result_RESULT_UNSPECIFIED:
return nil, fmt.Errorf("Failed to aggregate proofs %s, %w, input 1 %s, input 2 %s",
msg.GenAggregatedProofResponse.String(), ErrUnspecified, inputProof1, inputProof2)
case pb.Result_OK:
case pb.Result_RESULT_OK:
return &msg.GenAggregatedProofResponse.Id, nil
case pb.Result_ERROR:
case pb.Result_RESULT_ERROR:
return nil, fmt.Errorf("Failed to aggregate proofs %s, %w, input 1 %s, input 2 %s",
msg.GenAggregatedProofResponse.String(), ErrBadRequest, inputProof1, inputProof2)
case pb.Result_INTERNAL_ERROR:
case pb.Result_RESULT_INTERNAL_ERROR:
return nil, fmt.Errorf("Failed to aggregate proofs %s, %w, input 1 %s, input 2 %s",
msg.GenAggregatedProofResponse.String(), ErrProverInternalError, inputProof1, inputProof2)
default:
Expand Down Expand Up @@ -180,15 +194,15 @@ func (p *Prover) FinalProof(inputProof string, aggregatorAddr string) (*string,

if msg, ok := res.Response.(*pb.ProverMessage_GenFinalProofResponse); ok {
switch msg.GenFinalProofResponse.Result {
case pb.Result_UNSPECIFIED:
case pb.Result_RESULT_UNSPECIFIED:
return nil, fmt.Errorf("Failed to generate final proof %s, %w, input %s",
msg.GenFinalProofResponse.String(), ErrUnspecified, inputProof)
case pb.Result_OK:
case pb.Result_RESULT_OK:
return &msg.GenFinalProofResponse.Id, nil
case pb.Result_ERROR:
case pb.Result_RESULT_ERROR:
return nil, fmt.Errorf("Failed to generate final proof %s, %w, input %s",
msg.GenFinalProofResponse.String(), ErrBadRequest, inputProof)
case pb.Result_INTERNAL_ERROR:
case pb.Result_RESULT_INTERNAL_ERROR:
return nil, fmt.Errorf("Failed to generate final proof %s, %w, input %s",
msg.GenFinalProofResponse.String(), ErrProverInternalError, inputProof)
default:
Expand All @@ -213,15 +227,15 @@ func (p *Prover) CancelProofRequest(proofID string) error {
}
if msg, ok := res.Response.(*pb.ProverMessage_CancelResponse); ok {
switch msg.CancelResponse.Result {
case pb.Result_UNSPECIFIED:
case pb.Result_RESULT_UNSPECIFIED:
return fmt.Errorf("Failed to cancel proof id [%s], %w, %s",
proofID, ErrUnspecified, msg.CancelResponse.String())
case pb.Result_OK:
case pb.Result_RESULT_OK:
return nil
case pb.Result_ERROR:
case pb.Result_RESULT_ERROR:
return fmt.Errorf("Failed to cancel proof id [%s], %w, %s",
proofID, ErrBadRequest, msg.CancelResponse.String())
case pb.Result_INTERNAL_ERROR:
case pb.Result_RESULT_INTERNAL_ERROR:
return fmt.Errorf("Failed to cancel proof id [%s], %w, %s",
proofID, ErrProverInternalError, msg.CancelResponse.String())
default:
Expand Down Expand Up @@ -279,24 +293,24 @@ func (p *Prover) waitProof(ctx context.Context, proofID string) (*pb.GetProofRes
}
if msg, ok := res.Response.(*pb.ProverMessage_GetProofResponse); ok {
switch msg.GetProofResponse.Result {
case pb.GetProofResponse_PENDING:
case pb.GetProofResponse_RESULT_PENDING:
time.Sleep(p.proofStatePollingInterval.Duration)
continue
case pb.GetProofResponse_UNSPECIFIED:
case pb.GetProofResponse_RESULT_UNSPECIFIED:
return nil, fmt.Errorf("Failed to get proof ID: %s, %w, prover response: %s",
proofID, ErrUnspecified, msg.GetProofResponse.String())
case pb.GetProofResponse_COMPLETED_OK:
case pb.GetProofResponse_RESULT_COMPLETED_OK:
return msg.GetProofResponse, nil
case pb.GetProofResponse_ERROR:
case pb.GetProofResponse_RESULT_ERROR:
return nil, fmt.Errorf("Failed to get proof with ID %s, %w, prover response: %s",
proofID, ErrBadRequest, msg.GetProofResponse.String())
case pb.GetProofResponse_COMPLETED_ERROR:
case pb.GetProofResponse_RESULT_COMPLETED_ERROR:
return nil, fmt.Errorf("Failed to get proof with ID %s, %w, prover response: %s",
proofID, ErrProverCompletedError, msg.GetProofResponse.String())
case pb.GetProofResponse_INTERNAL_ERROR:
case pb.GetProofResponse_RESULT_INTERNAL_ERROR:
return nil, fmt.Errorf("Failed to get proof ID: %s, %w, prover response: %s",
proofID, ErrProverInternalError, msg.GetProofResponse.String())
case pb.GetProofResponse_CANCEL:
case pb.GetProofResponse_RESULT_CANCEL:
return nil, fmt.Errorf("Proof generation was cancelled for proof ID %s, %w, prover response: %s",
proofID, ErrProofCanceled, msg.GetProofResponse.String())
default:
Expand Down
25 changes: 23 additions & 2 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"fmt"
"math"
"net"
"net/http"
"os"
Expand Down Expand Up @@ -78,12 +79,30 @@ func start(cliCtx *cli.Context) error {
if err != nil {
log.Fatal(err)
}
// Read Fork ID FROM POE SC
// TODO: Uncomment when the POE SC is implemented
/*
currentForkID, err := etherman.GetL2ForkID()
if err != nil {
log.Fatal(err)
}

forkIDIntervals, err := etherman.GetL2ForkIDIntervals()
if err != nil {
log.Fatal(err)
}
*/

currentForkID := c.DefaultForkID
forkIDIntervals := []state.ForkIDInterval{{FromBatchNumber: 0, ToBatchNumber: math.MaxUint64, ForkId: c.DefaultForkID}}

c.Aggregator.ChainID = l2ChainID
c.Aggregator.ForkId = currentForkID
c.RPC.ChainID = l2ChainID
log.Infof("Chain ID read from POE SC = %v", l2ChainID)

ctx := context.Background()
st := newState(ctx, c, l2ChainID, stateSqlDB)
st := newState(ctx, c, l2ChainID, currentForkID, forkIDIntervals, stateSqlDB)

ethTxManagerStorage, err := ethtxmanager.NewPostgresStorage(c.StateDB)
if err != nil {
Expand Down Expand Up @@ -261,7 +280,7 @@ func waitSignal(cancelFuncs []context.CancelFunc) {
}
}

func newState(ctx context.Context, c *config.Config, l2ChainID uint64, sqlDB *pgxpool.Pool) *state.State {
func newState(ctx context.Context, c *config.Config, l2ChainID uint64, currentForkID uint64, forkIDIntervals []state.ForkIDInterval, sqlDB *pgxpool.Pool) *state.State {
stateDb := state.NewPostgresStorage(sqlDB)
executorClient, _, _ := executor.NewExecutorClient(ctx, c.Executor)
stateDBClient, _, _ := merkletree.NewMTDBServiceClient(ctx, c.MTClient)
Expand All @@ -270,6 +289,8 @@ func newState(ctx context.Context, c *config.Config, l2ChainID uint64, sqlDB *pg
stateCfg := state.Config{
MaxCumulativeGasUsed: c.Sequencer.MaxCumulativeGasUsed,
ChainID: l2ChainID,
CurrentForkID: currentForkID,
ForkIDIntervals: forkIDIntervals,
}

st := state.NewState(stateCfg, stateDb, executorClient, stateTree)
Expand Down
3 changes: 2 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ const (

// Config represents the configuration of the entire Hermez Node
type Config struct {
IsTrustedSequencer bool `mapstructure:"IsTrustedSequencer"`
IsTrustedSequencer bool `mapstructure:"IsTrustedSequencer"`
DefaultForkID uint64 `mapstructure:"DefaultForkID"`
Log log.Config
Etherman etherman.Config
EthTxManager ethtxmanager.Config
Expand Down
1 change: 1 addition & 0 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
// DefaultValues is the default configuration
const DefaultValues = `
IsTrustedSequencer = false
DefaultForkID = 1

[Log]
Environment = "development" # "production" or "development"
Expand Down
1 change: 1 addition & 0 deletions config/environments/local/local.node.config.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
IsTrustedSequencer = false
DefaultForkID = 1

[Log]
Environment = "development" # "production" or "development"
Expand Down
1 change: 0 additions & 1 deletion config/environments/public/public.prover.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@

"inputFile": "input_executor.json",
"outputPath": "output",
"romFile": "rom.json",
"cmPolsFile_disabled": "zkevm.commit",
"cmPolsFileC12a_disabled": "zkevm.c12a.commit",
"cmPolsFileRecursive1_disabled": "zkevm.recursive1.commit",
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ services:

zkevm-prover:
container_name: zkevm-prover
image: hermeznetwork/zkevm-prover:9c4a1fe
image: hermeznetwork/zkevm-prover:c136cc1
ports:
- 50061:50061 # MT
- 50071:50071 # Executor
Expand Down
2 changes: 1 addition & 1 deletion etherman/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var (
//ErrContentLengthTooLarge content length is too large
ErrContentLengthTooLarge = errors.New("content length too large")
//ErrTimestampMustBeInsideRange Timestamp must be inside range
ErrTimestampMustBeInsideRange = errors.New("Timestamp must be inside range")
ErrTimestampMustBeInsideRange = errors.New("timestamp must be inside range")
//ErrInsufficientAllowance insufficient allowance
ErrInsufficientAllowance = errors.New("insufficient allowance")
//ErrBothGasPriceAndMaxFeeGasAreSpecified both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified
Expand Down
13 changes: 13 additions & 0 deletions etherman/etherman.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"io/ioutil"
"math"
"math/big"
"path/filepath"
"strings"
Expand Down Expand Up @@ -838,6 +839,18 @@ func (etherMan *Client) GetL2ChainID() (uint64, error) {
return etherMan.PoE.ChainID(&bind.CallOpts{Pending: false})
}

// GetL2ForkID returns current L2 Fork ID
func (etherMan *Client) GetL2ForkID() (uint64, error) {
// TODO: implement this
return 1, nil
}

// GetL2ForkIDIntervals return L2 Fork ID intervals
func (etherMan *Client) GetL2ForkIDIntervals() ([]state.ForkIDInterval, error) {
// TODO: implement this
return []state.ForkIDInterval{{FromBatchNumber: 0, ToBatchNumber: math.MaxUint64, ForkId: 1}}, nil
}

// GetL1GasPrice gets the l1 gas price
func (etherMan *Client) GetL1GasPrice(ctx context.Context) *big.Int {
// Get gasPrice from providers
Expand Down
2 changes: 1 addition & 1 deletion merkletree/pb/statedb.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions merkletree/pb/statedb_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading