Skip to content

Commit

Permalink
Hotfix/v0.1.3 (#2173)
Browse files Browse the repository at this point in the history
* fix concurrent web socket writes

* fix eth_syncing

* fix custom trace internal tx call error handling and update prover

* add test to custom tracer depth issue; fix internal call error and gas used

* fix custom tracer for internal tx with error and no more steps after it

* remove debug code

* Make max grpc message size configurable  (#2179)

* make max grpc message size configurable

* fix state tests

* fix tests

* fix tests

* get SequencerNodeURI from SC if empty and not IsTrustedSequencer

* Optimize trace (#2183)

* optimize trace

* fix memory reading

* update docker image

* update prover image

* fix converter

* fix memory

* fix step memory

* fix structlogs

* fix structlogs

* fix structlogs

* fix structlogs

* fix structlogs

* fix structlogs

* fix structlogs

* fix structlogs

* update prover image

* fix struclogs

* fix memory size

* fix memory size

* fix memory size

* refactor memory resize

* refactor memory resize

* move log for the best fitting tx (#2192)

* fix load zkCounters from pool

* remove unnecessary log.info

* add custom tracer support to CREATES opcode without depth increase (#2213)

* logs

* fix getting stateroot from previous batch (GetWIPBatch)

* logs

* Fix GetWipBatch when previous last batch is a forced batch

* fix forcedBatch trusted state

* Revert "fix getting stateroot from previous batch (GetWIPBatch)"

This reverts commit 860f0e7.

* force GHA

* add pool limits (#2189)

* Hotfix/batch l2 data (#2223)

* Fix BatchL2Data

* Force GHA

---------

Co-authored-by: Toni Ramírez <[email protected]>
Co-authored-by: agnusmor <[email protected]>
Co-authored-by: agnusmor <[email protected]>
Co-authored-by: Alonso <[email protected]>
Co-authored-by: Alonso Rodriguez <[email protected]>
  • Loading branch information
6 people authored Jun 26, 2023
1 parent c3d0bd4 commit c7aabd4
Show file tree
Hide file tree
Showing 51 changed files with 2,096 additions and 353 deletions.
15 changes: 13 additions & 2 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func start(cliCtx *cli.Context) error {
for _, a := range cliCtx.StringSlice(config.FlagHTTPAPI) {
apis[a] = true
}
go runJSONRPCServer(*c, l2ChainID, poolInstance, st, apis)
go runJSONRPCServer(*c, etherman, l2ChainID, poolInstance, st, apis)
case SYNCHRONIZER:
ev.Component = event.Component_Synchronizer
ev.Description = "Running synchronizer"
Expand Down Expand Up @@ -314,9 +314,20 @@ func runSynchronizer(cfg config.Config, etherman *etherman.Client, ethTxManager
}
}

func runJSONRPCServer(c config.Config, chainID uint64, pool *pool.Pool, st *state.State, apis map[string]bool) {
func runJSONRPCServer(c config.Config, etherman *etherman.Client, chainID uint64, pool *pool.Pool, st *state.State, apis map[string]bool) {
var err error
storage := jsonrpc.NewStorage()
c.RPC.MaxCumulativeGasUsed = c.Sequencer.MaxCumulativeGasUsed
if !c.IsTrustedSequencer {
if c.RPC.SequencerNodeURI == "" {
log.Debug("getting trusted sequencer URL from smc")
c.RPC.SequencerNodeURI, err = etherman.GetTrustedSequencerURL()
if err != nil {
log.Fatal("error getting trusted sequencer URI. Error: %v", err)
}
}
log.Debug("SequencerNodeURI ", c.RPC.SequencerNodeURI)
}

if err := jsonrpc.NewServer(c.RPC, chainID, pool, st, storage, apis).Start(); err != nil {
log.Fatal(err)
Expand Down
12 changes: 12 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,14 @@ func Test_Defaults(t *testing.T) {
path: "Pool.PollMinAllowedGasPriceInterval",
expectedValue: types.NewDuration(15 * time.Second),
},
{
path: "Pool.AccountQueue",
expectedValue: uint64(64),
},
{
path: "Pool.GlobalQueue",
expectedValue: uint64(1024),
},
{
path: "Pool.DB.User",
expectedValue: "pool_user",
Expand Down Expand Up @@ -386,6 +394,10 @@ func Test_Defaults(t *testing.T) {
path: "Executor.URI",
expectedValue: "zkevm-prover:50071",
},
{
path: "Executor.MaxGRPCMessageSize",
expectedValue: int(100000000),
},
{
path: "Metrics.Host",
expectedValue: "0.0.0.0",
Expand Down
3 changes: 3 additions & 0 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ MaxTxDataBytesSize=100000
DefaultMinGasPriceAllowed = 1000000000
MinAllowedGasPriceInterval = "5m"
PollMinAllowedGasPriceInterval = "15s"
AccountQueue = 64
GlobalQueue = 1024
[Pool.DB]
User = "pool_user"
Password = "pool_password"
Expand Down Expand Up @@ -139,6 +141,7 @@ URI = "zkevm-prover:50061"
[Executor]
URI = "zkevm-prover:50071"
MaxGRPCMessageSize = 100000000
[Metrics]
Host = "0.0.0.0"
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
Expand Up @@ -131,6 +131,7 @@ URI = "zkevm-prover:50061"

[Executor]
URI = "zkevm-prover:50071"
MaxGRPCMessageSize = 100000000

[Metrics]
Host = "0.0.0.0"
Expand Down
1 change: 1 addition & 0 deletions config/environments/mainnet/public.node.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ URI = "zkevm-prover:50061"

[Executor]
URI = "zkevm-prover:50071"
MaxGRPCMessageSize = 100000000

[Metrics]
Host = "0.0.0.0"
Expand Down
1 change: 1 addition & 0 deletions config/environments/public/public.node.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ URI = "zkevm-prover:50061"

[Executor]
URI = "zkevm-prover:50071"
MaxGRPCMessageSize = 100000000

[Metrics]
Host = "0.0.0.0"
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ services:
zkevm-prover:
container_name: zkevm-prover
restart: unless-stopped
image: hermeznetwork/zkevm-prover:v1.1.4-fork.4
image: hermeznetwork/zkevm-prover:v1.1.5-RC4-fork.4
depends_on:
zkevm-state-db:
condition: service_healthy
Expand Down
34 changes: 26 additions & 8 deletions jsonrpc/endpoints_debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/0xPolygonHermez/zkevm-node/jsonrpc/types"
"github.com/0xPolygonHermez/zkevm-node/log"
"github.com/0xPolygonHermez/zkevm-node/state"
"github.com/0xPolygonHermez/zkevm-node/state/runtime/fakevm"
"github.com/0xPolygonHermez/zkevm-node/state/runtime/instrumentation"
"github.com/ethereum/go-ethereum/common"
ethTypes "github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -195,6 +196,7 @@ func (d *DebugEndpoints) buildTraceTransaction(ctx context.Context, hash common.

func (d *DebugEndpoints) buildStructLogs(stateStructLogs []instrumentation.StructLog, cfg traceConfig) []StructLogRes {
structLogs := make([]StructLogRes, 0, len(stateStructLogs))
memory := fakevm.NewMemory()
for _, structLog := range stateStructLogs {
errRes := ""
if structLog.Err != nil {
Expand Down Expand Up @@ -231,15 +233,31 @@ func (d *DebugEndpoints) buildStructLogs(stateStructLogs []instrumentation.Struc
}

if cfg.EnableMemory {
const memoryChunkSize = 32
memory := make([]string, 0, len(structLog.Memory))
for i := 0; i < len(structLog.Memory); i = i + memoryChunkSize {
slice32Bytes := make([]byte, memoryChunkSize)
copy(slice32Bytes, structLog.Memory[i:i+memoryChunkSize])
memoryStringItem := hex.EncodeToString(slice32Bytes)
memory = append(memory, memoryStringItem)
memory.Resize(uint64(structLog.MemorySize))
if len(structLog.Memory) > 0 {
memory.Set(uint64(structLog.MemoryOffset), uint64(len(structLog.Memory)), structLog.Memory)
}

if structLog.MemorySize > 0 {
// Populate the structLog memory
structLog.Memory = memory.Data()

// Convert memory to string array
const memoryChunkSize = 32
memoryArray := make([]string, 0, len(structLog.Memory))

for i := 0; i < len(structLog.Memory); i = i + memoryChunkSize {
slice32Bytes := make([]byte, memoryChunkSize)
copy(slice32Bytes, structLog.Memory[i:i+memoryChunkSize])
memoryStringItem := hex.EncodeToString(slice32Bytes)
memoryArray = append(memoryArray, memoryStringItem)
}

structLogRes.Memory = &memoryArray
} else {
memory = fakevm.NewMemory()
structLogRes.Memory = &[]string{}
}
structLogRes.Memory = &memory
}

if !cfg.DisableStorage && len(structLog.Storage) > 0 {
Expand Down
2 changes: 1 addition & 1 deletion jsonrpc/endpoints_eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ func (e *EthEndpoints) Syncing() (interface{}, types.Error) {
return rpcErrorResponse(types.DefaultErrorCode, "failed to get syncing info from state", err)
}

if syncInfo.CurrentBlockNumber == syncInfo.LastBlockNumberSeen {
if syncInfo.CurrentBlockNumber >= syncInfo.LastBlockNumberSeen {
return false, nil
}

Expand Down
26 changes: 26 additions & 0 deletions jsonrpc/endpoints_eth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1862,6 +1862,32 @@ func TestSyncing(t *testing.T) {
Once()
},
},
{
Name: "get syncing information successfully when synced and trusted state is ahead",
ExpectedResult: nil,
ExpectedError: nil,
SetupMocks: func(m *mocksWrapper, tc testCase) {
m.DbTx.
On("Commit", context.Background()).
Return(nil).
Once()

m.State.
On("BeginStateTransaction", context.Background()).
Return(m.DbTx, nil).
Once()

m.State.
On("GetLastL2BlockNumber", context.Background(), m.DbTx).
Return(uint64(10), nil).
Once()

m.State.
On("GetSyncingInfo", context.Background(), m.DbTx).
Return(state.SyncingInfo{InitialSyncingBlock: 1, CurrentBlockNumber: 2, LastBlockNumberSeen: 1, LastBlockNumberConsolidated: 1}, nil).
Once()
},
},
}

for _, testCase := range testCases {
Expand Down
1 change: 0 additions & 1 deletion jsonrpc/endpoints_zkevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ func (z *ZKEVMEndpoints) VerifiedBatchNumber() (interface{}, types.Error) {
if err != nil {
return "0x0", types.NewRPCError(types.DefaultErrorCode, "failed to get the last verified batch number from state")
}

return hex.EncodeUint64(lastBatch.BatchNumber), nil
})
}
Expand Down
18 changes: 18 additions & 0 deletions jsonrpc/endpoints_zkevm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ func TestGetBatchByNumber(t *testing.T) {
Timestamp: 1,
SendSequencesTxHash: ptrHash(common.HexToHash("0x10")),
VerifyBatchTxHash: ptrHash(common.HexToHash("0x20")),
BatchL2Data: hexToBytes("0x04"),
},
ExpectedError: nil,
SetupMocks: func(s *mockedServer, m *mocksWrapper, tc *testCase) {
Expand All @@ -668,6 +669,7 @@ func TestGetBatchByNumber(t *testing.T) {
AccInputHash: common.HexToHash("0x3"),
GlobalExitRoot: common.HexToHash("0x4"),
Timestamp: time.Unix(1, 0),
BatchL2Data: hexToBytes("0x04"),
}

m.State.
Expand Down Expand Up @@ -772,6 +774,7 @@ func TestGetBatchByNumber(t *testing.T) {
Timestamp: 1,
SendSequencesTxHash: ptrHash(common.HexToHash("0x10")),
VerifyBatchTxHash: ptrHash(common.HexToHash("0x20")),
BatchL2Data: hexToBytes("0x04"),
},
ExpectedError: nil,
SetupMocks: func(s *mockedServer, m *mocksWrapper, tc *testCase) {
Expand All @@ -792,6 +795,7 @@ func TestGetBatchByNumber(t *testing.T) {
AccInputHash: common.HexToHash("0x3"),
GlobalExitRoot: common.HexToHash("0x4"),
Timestamp: time.Unix(1, 0),
BatchL2Data: hexToBytes("0x04"),
}

m.State.
Expand Down Expand Up @@ -869,13 +873,15 @@ func TestGetBatchByNumber(t *testing.T) {
WithTxDetail: true,
ExpectedResult: &types.Batch{
Number: 1,
ForcedBatchNumber: ptrArgUint64FromUint64(1),
Coinbase: common.HexToAddress("0x1"),
StateRoot: common.HexToHash("0x2"),
AccInputHash: common.HexToHash("0x3"),
GlobalExitRoot: common.HexToHash("0x4"),
Timestamp: 1,
SendSequencesTxHash: ptrHash(common.HexToHash("0x10")),
VerifyBatchTxHash: ptrHash(common.HexToHash("0x20")),
BatchL2Data: hexToBytes("0x04"),
},
ExpectedError: nil,
SetupMocks: func(s *mockedServer, m *mocksWrapper, tc *testCase) {
Expand All @@ -894,13 +900,16 @@ func TestGetBatchByNumber(t *testing.T) {
Return(uint64(tc.ExpectedResult.Number), nil).
Once()

var fb uint64 = 1
batch := &state.Batch{
BatchNumber: 1,
ForcedBatchNum: &fb,
Coinbase: common.HexToAddress("0x1"),
StateRoot: common.HexToHash("0x2"),
AccInputHash: common.HexToHash("0x3"),
GlobalExitRoot: common.HexToHash("0x4"),
Timestamp: time.Unix(1, 0),
BatchL2Data: hexToBytes("0x04"),
}

m.State.
Expand Down Expand Up @@ -1066,6 +1075,9 @@ func TestGetBatchByNumber(t *testing.T) {
err = json.Unmarshal(res.Result, &batch)
require.NoError(t, err)
assert.Equal(t, tc.ExpectedResult.Number.Hex(), batch["number"].(string))
if tc.ExpectedResult.ForcedBatchNumber != nil {
assert.Equal(t, tc.ExpectedResult.ForcedBatchNumber.Hex(), batch["forcedBatchNumber"].(string))
}
assert.Equal(t, tc.ExpectedResult.Coinbase.String(), batch["coinbase"].(string))
assert.Equal(t, tc.ExpectedResult.StateRoot.String(), batch["stateRoot"].(string))
assert.Equal(t, tc.ExpectedResult.GlobalExitRoot.String(), batch["globalExitRoot"].(string))
Expand All @@ -1074,6 +1086,7 @@ func TestGetBatchByNumber(t *testing.T) {
assert.Equal(t, tc.ExpectedResult.Timestamp.Hex(), batch["timestamp"].(string))
assert.Equal(t, tc.ExpectedResult.SendSequencesTxHash.String(), batch["sendSequencesTxHash"].(string))
assert.Equal(t, tc.ExpectedResult.VerifyBatchTxHash.String(), batch["verifyBatchTxHash"].(string))
assert.Equal(t, tc.ExpectedResult.BatchL2Data.Hex(), batch["batchL2Data"].(string))
batchTxs := batch["transactions"].([]interface{})
for i, txOrHash := range tc.ExpectedResult.Transactions {
switch batchTxOrHash := batchTxs[i].(type) {
Expand Down Expand Up @@ -1134,3 +1147,8 @@ func signTx(tx *ethTypes.Transaction, chainID uint64) *ethTypes.Transaction {
signedTx, _ := auth.Signer(auth.From, tx)
return signedTx
}

func hexToBytes(str string) []byte {
bytes, _ := hex.DecodeHex(str)
return bytes
}
4 changes: 4 additions & 0 deletions jsonrpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"io"
"net"
"net/http"
"sync"
"time"

"github.com/0xPolygonHermez/zkevm-node/jsonrpc/metrics"
Expand Down Expand Up @@ -365,6 +366,7 @@ func (s *Server) handleWs(w http.ResponseWriter, req *http.Request) {
}(wsConn)

log.Info("Websocket connection established")
var mu sync.Mutex
for {
msgType, message, err := wsConn.ReadMessage()
if err != nil {
Expand All @@ -382,6 +384,8 @@ func (s *Server) handleWs(w http.ResponseWriter, req *http.Request) {

if msgType == websocket.TextMessage || msgType == websocket.BinaryMessage {
go func() {
mu.Lock()
defer mu.Unlock()
resp, err := s.handler.HandleWs(message, wsConn)
if err != nil {
log.Error(fmt.Sprintf("Unable to handle WS request, %s", err.Error()))
Expand Down
8 changes: 8 additions & 0 deletions jsonrpc/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ func NewBlock(b *types.Block, fullTx bool) *Block {
// Batch structure
type Batch struct {
Number ArgUint64 `json:"number"`
ForcedBatchNumber *ArgUint64 `json:"forcedBatchNumber,omitempty"`
Coinbase common.Address `json:"coinbase"`
StateRoot common.Hash `json:"stateRoot"`
GlobalExitRoot common.Hash `json:"globalExitRoot"`
Expand All @@ -337,10 +338,12 @@ type Batch struct {
SendSequencesTxHash *common.Hash `json:"sendSequencesTxHash"`
VerifyBatchTxHash *common.Hash `json:"verifyBatchTxHash"`
Transactions []TransactionOrHash `json:"transactions"`
BatchL2Data ArgBytes `json:"batchL2Data"`
}

// NewBatch creates a Batch instance
func NewBatch(batch *state.Batch, virtualBatch *state.VirtualBatch, verifiedBatch *state.VerifiedBatch, receipts []types.Receipt, fullTx bool, ger *state.GlobalExitRoot) *Batch {
batchL2Data := batch.BatchL2Data
res := &Batch{
Number: ArgUint64(batch.BatchNumber),
GlobalExitRoot: batch.GlobalExitRoot,
Expand All @@ -351,6 +354,11 @@ func NewBatch(batch *state.Batch, virtualBatch *state.VirtualBatch, verifiedBatc
StateRoot: batch.StateRoot,
Coinbase: batch.Coinbase,
LocalExitRoot: batch.LocalExitRoot,
BatchL2Data: ArgBytes(batchL2Data),
}
if batch.ForcedBatchNum != nil {
fb := ArgUint64(*batch.ForcedBatchNum)
res.ForcedBatchNumber = &fb
}

if virtualBatch != nil {
Expand Down
Loading

0 comments on commit c7aabd4

Please sign in to comment.