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

Merge upstream v2.60.0 beta8 #163

Draft
wants to merge 23 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
fd88d87
WIP: add unit test to stage l1_sequencer_sync
tclemos Nov 6, 2024
db2fe26
implement test cases for TestSpawnL1SequencerSyncStage
tclemos Nov 8, 2024
97ec39c
add more test cases for TestSpawnL1SequencerSyncStage
tclemos Nov 9, 2024
f379005
Merge branch 'zkevm' into test/stage-l1-sequencer-sync
tclemos Nov 9, 2024
05b07ac
Merge pull request #1435 from 0xPolygonHermez/test/stage-l1-sequencer…
tclemos Nov 11, 2024
a3176d1
fix(zkevm_api): feed accinputhash back to accinputhash calc (#1438)
revitteth Nov 11, 2024
0f99eaf
tweak(zkevm_api): check if sequencer for closed batch (#1439)
revitteth Nov 11, 2024
17ca7c9
tweak(zkevm_api): improve accinput missing batch log (#1441)
revitteth Nov 11, 2024
59c1e3f
fall back method for checking batch closed state (#1442)
hexoscott Nov 12, 2024
bcc110d
fix: setting correct timeout on buffer emptying (#1437)
V-Staykov Nov 12, 2024
73591fe
fix: use stage_execute block numbers for a sequencer in rpc calls (#1…
V-Staykov Nov 12, 2024
8884d2b
increase timeouts for unwind tests (#1445)
hexoscott Nov 12, 2024
4bc51c4
feat: add mock witness generation (#1436)
MorettiGeorgiev Nov 12, 2024
4792c13
tweak(zkevm_api): accinput batch 0/1 0x00...0 (#1446)
revitteth Nov 12, 2024
c33bf57
feat: rollupaddress and rollupmanageraddress rpc method
jhkimqd Nov 12, 2024
4735dec
test: add unit tests for zkevm_getrollupaddress and zkevm_getrollupma…
jhkimqd Nov 12, 2024
eb66298
chore: cleanup
jhkimqd Nov 12, 2024
b1eed6d
chore: lint
jhkimqd Nov 12, 2024
83d4db2
fix: health check block timestamp fix (#1448)
V-Staykov Nov 12, 2024
d26a745
Merge pull request #1447 from jhkimqd/jihwan/new-zkevm-api
jhkimqd Nov 12, 2024
797ea50
Add CPU monitor in CI (#1389)
cffls Nov 12, 2024
4dbfc3b
bug fix in close batch status for RPC node (#1449)
hexoscott Nov 12, 2024
9569768
Merge branch 'upstream/v2.60.0-beta8' into zjg/basedev-merge-v2.60.0-…
zjg555543 Nov 13, 2024
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
136 changes: 136 additions & 0 deletions .github/scripts/cpu_monitor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#!/bin/bash

# Configuration
THRESHOLD=80
MEASUREMENTS_FILE="/tmp/cpu_measurements.txt"
MONITOR_INTERVAL=5 # seconds
PROCESS_NAME="cdk-erigon"
DETAILED_LOG="/tmp/cpu_detailed.log"

# Function to get CPU usage for all matching processes
get_process_cpu() {
# Clear previous detailed log
> "$DETAILED_LOG"

# Get PIDs of cdk-erigon processes
pids=$(pgrep -f "[c]dk-erigon")

if [ -n "$pids" ]; then
# Use top in batch mode for each PID to get current CPU usage
for pid in $pids; do
# Get process command
if [[ "$OSTYPE" == "darwin"* ]]; then
cmd=$(ps -p $pid -o command=)
cpu=$(top -l 1 -pid $pid | tail -1 | awk '{print $3}')
else
cmd=$(ps -p $pid -o cmd=)
cpu=$(top -b -n 1 -p $pid | tail -1 | awk '{print $9}')
fi
# Get current CPU usage
echo "$pid $cpu $cmd" >> "$DETAILED_LOG"
done
fi

# Sum total CPU usage
total_cpu=$(awk '{sum += $2} END {printf "%.1f", sum}' "$DETAILED_LOG")

# Return 0 if no process found
if [ -z "$total_cpu" ]; then
echo "0.0"
else
echo "$total_cpu"
fi
}

# Function to show current process details
show_process_details() {
if [ -s "$DETAILED_LOG" ]; then
echo "Individual process details:"
printf "%-10s %-8s %-s\n" "PID" "CPU%" "Command"
echo "----------------------------------------"
while read -r line; do
pid=$(echo "$line" | awk '{print $1}')
cpu=$(echo "$line" | awk '{print $2}')
cmd=$(echo "$line" | cut -d' ' -f3-)
printf "%-10s %-8.1f %-s\n" "$pid" "$cpu" "$cmd"
done < "$DETAILED_LOG"
echo "----------------------------------------"
else
echo "No $PROCESS_NAME processes found"
fi
}

# Function to analyze CPU measurements
analyze_cpu() {
if [ -f "$MEASUREMENTS_FILE" ]; then
# Calculate statistics
avg_cpu=$(awk '{ sum += $1 } END { print sum/NR }' "$MEASUREMENTS_FILE")
avg_cpu_rounded=$(printf "%.1f" "$avg_cpu")
max_cpu=$(awk 'BEGIN{max=0} {if($1>max) max=$1} END{print max}' "$MEASUREMENTS_FILE")
measurement_count=$(wc -l < "$MEASUREMENTS_FILE")

echo ""
echo "=== CPU Usage Analysis for all $PROCESS_NAME processes ==="
echo "Number of measurements: $measurement_count"
echo "Average Combined CPU Usage: $avg_cpu_rounded%"
echo "Peak Combined CPU Usage: $max_cpu%"
echo "Threshold: $THRESHOLD%"

# Get final process details for the report
echo ""
echo "Final process state:"
show_process_details

# Compare with threshold
if [ "$(echo "$avg_cpu > $THRESHOLD" | bc -l)" -eq 1 ]; then
echo ""
echo "ERROR: Average CPU usage ($avg_cpu_rounded%) exceeded threshold of $THRESHOLD%"
cleanup_and_exit 1
else
echo ""
echo "SUCCESS: CPU usage ($avg_cpu_rounded%) is within threshold of $THRESHOLD%"
cleanup_and_exit 0
fi
else
echo "ERROR: No CPU measurements found at $MEASUREMENTS_FILE"
cleanup_and_exit 1
fi
}

# Function to clean up and exit
cleanup_and_exit() {
exit_code=$1
rm -f "$DETAILED_LOG"
exit $exit_code
}

# Function to handle interruption
handle_interrupt() {
echo ""
echo "Monitoring interrupted. Analyzing collected data..."
analyze_cpu
}

# Set up trap for various signals
trap handle_interrupt TERM INT

# Clear measurements file
> "$MEASUREMENTS_FILE"
> "$DETAILED_LOG"

echo "Starting CPU monitoring for all '$PROCESS_NAME' processes"
echo "Storing measurements in $MEASUREMENTS_FILE"
echo "Monitoring interval: ${MONITOR_INTERVAL}s"
echo "Press Ctrl+C to stop monitoring and see analysis"
echo ""

# Start monitoring loop
while true; do
# Get CPU usage for all matching processes
cpu_usage=$(get_process_cpu)
echo "$cpu_usage" >> "$MEASUREMENTS_FILE"
echo "$(date '+%Y-%m-%d %H:%M:%S') - Combined CPU Usage: $cpu_usage%"
show_process_details
echo ""
sleep "$MONITOR_INTERVAL"
done
17 changes: 17 additions & 0 deletions .github/workflows/ci_zkevm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,23 @@ jobs:
run: |
kurtosis run --enclave cdk-v1 --image-download always . '{"args": {"data_availability_mode": "${{ matrix.da-mode }}", "cdk_erigon_node_image": "cdk-erigon:local"}}'

- name: Run process with CPU monitoring
working-directory: ./cdk-erigon
run: |
# Start monitoring in background
bash ./.github/scripts/cpu_monitor.sh &
monitor_pid=$!

# Wait for 30 seconds
sleep 30

# Stop monitoring and get analysis
kill -TERM $monitor_pid
wait $monitor_pid || {
echo "CPU usage exceeded threshold!"
exit 1
}

- name: Monitor verified batches
working-directory: ./kurtosis-cdk
shell: bash
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ lint:
@./erigon-lib/tools/golangci_lint.sh
@./erigon-lib/tools/mod_tidy_check.sh

cpu_monitor:
@.github/scripts/cpu_monitor.sh

## clean: cleans the go cache, build dir, libmdbx db dir
clean:
go clean -cache
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,15 @@ Useful config entries:
- `zkevm.sync-limit`: This will ensure the network only syncs to a given block height.
- `debug.timers`: This will enable debug timers in the logs to help with performance tuning. Recording timings of witness generation, etc. at INFO level.

Metrics and pprof configuration flags:

- `metrics:` Enables or disables the metrics collection. Set to true to enable.
- `metrics.addr`: The address on which the metrics server will listen. Default is "0.0.0.0".
- `metrics.port`: The port on which the metrics server will listen. Default is 6060.
- `pprof`: Enables or disables the pprof profiling. Set to true to enable.
- `pprof.addr`: The address on which the pprof server will listen. Default is "0.0.0.0".
- `pprof.port`: The port on which the pprof server will listen. Default is 6061.

***


Expand Down
10 changes: 6 additions & 4 deletions cmd/rpcdaemon/health/check_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"net/http"

"github.com/ledgerwatch/erigon-lib/common/hexutil"

"github.com/ledgerwatch/erigon/rpc"
)

Expand All @@ -20,13 +22,13 @@ func checkTime(
if err != nil {
return err
}
timestamp := 0
timestamp := uint64(0)
if ts, ok := i["timestamp"]; ok {
if cs, ok := ts.(uint64); ok {
timestamp = int(cs)
if cs, ok := ts.(hexutil.Uint64); ok {
timestamp = cs.Uint64()
}
}
if timestamp < seconds {
if timestamp < uint64(seconds) {
return fmt.Errorf("%w: got ts: %d, need: %d", errTimestampTooOld, timestamp, seconds)
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/rpcdaemon/health/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func TestProcessHealthcheckIfNeeded_HeadersTests(t *testing.T) {
netApiResponse: hexutil.Uint(1),
netApiError: nil,
ethApiBlockResult: map[string]interface{}{
"timestamp": uint64(time.Now().Add(-10 * time.Second).Unix()),
"timestamp": hexutil.Uint64(time.Now().Add(-10 * time.Second).Unix()),
},
ethApiBlockError: nil,
ethApiSyncingResult: false,
Expand All @@ -264,7 +264,7 @@ func TestProcessHealthcheckIfNeeded_HeadersTests(t *testing.T) {
netApiResponse: hexutil.Uint(1),
netApiError: nil,
ethApiBlockResult: map[string]interface{}{
"timestamp": uint64(time.Now().Add(-1 * time.Hour).Unix()),
"timestamp": hexutil.Uint64(time.Now().Add(-1 * time.Hour).Unix()),
},
ethApiBlockError: nil,
ethApiSyncingResult: false,
Expand All @@ -283,7 +283,7 @@ func TestProcessHealthcheckIfNeeded_HeadersTests(t *testing.T) {
netApiResponse: hexutil.Uint(1),
netApiError: nil,
ethApiBlockResult: map[string]interface{}{
"timestamp": uint64(time.Now().Add(1 * time.Hour).Unix()),
"timestamp": hexutil.Uint64(time.Now().Add(1 * time.Hour).Unix()),
},
ethApiBlockError: nil,
ethApiSyncingResult: false,
Expand Down Expand Up @@ -319,7 +319,7 @@ func TestProcessHealthcheckIfNeeded_HeadersTests(t *testing.T) {
netApiResponse: hexutil.Uint(10),
netApiError: nil,
ethApiBlockResult: map[string]interface{}{
"timestamp": uint64(time.Now().Add(1 * time.Second).Unix()),
"timestamp": hexutil.Uint64(time.Now().Add(1 * time.Second).Unix()),
},
ethApiBlockError: nil,
ethApiSyncingResult: false,
Expand Down
5 changes: 5 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,11 @@ var (
Usage: "Seal the batch immediately when detecting a counter overflow",
Value: false,
}
MockWitnessGeneration = cli.BoolFlag{
Name: "zkevm.mock-witness-generation",
Usage: "Mock the witness generation",
Value: false,
}
ACLPrintHistory = cli.IntFlag{
Name: "acl.print-history",
Usage: "Number of entries to print from the ACL history on node start up",
Expand Down
2 changes: 2 additions & 0 deletions docs/endpoints/endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ If the endpoint is not in the list below, it means this specific endpoint is not
- zkevm_getL2BlockInfoTree
- zkevm_getLatestGlobalExitRoot
- zkevm_getProverInput
- zkevm_getRollupAddress
- zkevm_getRollupManagerAddress
- zkevm_getVersionHistory
- zkevm_getWitness
- zkevm_isBlockConsolidated
Expand Down
1 change: 1 addition & 0 deletions eth/ethconfig/config_zkevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ type Zk struct {
InfoTreeUpdateInterval time.Duration
BadBatches []uint64
SealBatchImmediatelyOnOverflow bool
MockWitnessGeneration bool
}

var DefaultZkConfig = Zk{
Expand Down
5 changes: 3 additions & 2 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@ all: ## Runs a full node
$(RUN_DOCKER_BRIDGE_COIN_KAFKA)
sleep 3
$(RUN_DOCKER_DATA_AVAILABILITY)
$(RUN_DOCKER_APPROVE)

# app services
#sleep 3
#$(RUN_DOCKER_STATELESS_EXECUTOR)
$(RUN_DOCKER_STATELESS_EXECUTOR)
$(RUN_DOCKER_SEQ)
$(RUN_DOCKER_PROVER)
sleep 10
Expand All @@ -97,7 +98,7 @@ all: ## Runs a full node
$(RUN_DOCKER_RPC)

# bridge services
sleep 3
sleep 30
$(RUN_DOCKER_BRIDGE_SERVICE)
sleep 3
$(RUN_DOCKER_BRIDGE_UI)
Expand Down
1 change: 1 addition & 0 deletions turbo/cli/default_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,4 +328,5 @@ var DefaultFlags = []cli.Flag{
&utils.ACLPrintHistory,
&utils.InfoTreeUpdateInterval,
&utils.SealBatchImmediatelyOnOverflow,
&utils.MockWitnessGeneration,
}
1 change: 1 addition & 0 deletions turbo/cli/flags_zkevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ func ApplyFlagsForZkConfig(ctx *cli.Context, cfg *ethconfig.Config) {
ACLPrintHistory: ctx.Int(utils.ACLPrintHistory.Name),
InfoTreeUpdateInterval: ctx.Duration(utils.InfoTreeUpdateInterval.Name),
SealBatchImmediatelyOnOverflow: ctx.Bool(utils.SealBatchImmediatelyOnOverflow.Name),
MockWitnessGeneration: ctx.Bool(utils.MockWitnessGeneration.Name),
}

// For X Layer
Expand Down
2 changes: 1 addition & 1 deletion turbo/jsonrpc/bor_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func getHeaderByNumber(ctx context.Context, number rpc.BlockNumber, api *BorImpl
return block.Header(), nil
}

blockNum, _, _, err := rpchelper.GetBlockNumber(rpc.BlockNumberOrHashWithNumber(number), tx, api.filters)
blockNum, _, _, err := rpchelper.GetBlockNumber_zkevm(rpc.BlockNumberOrHashWithNumber(number), tx, api.filters)
if err != nil {
return nil, err
}
Expand Down
5 changes: 3 additions & 2 deletions turbo/jsonrpc/debug_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@ func (api *PrivateDebugAPIImpl) GetRawHeader(ctx context.Context, blockNrOrHash
return nil, err
}
defer tx.Rollback()
n, h, _, err := rpchelper.GetBlockNumber(blockNrOrHash, tx, api.filters)

n, h, _, err := rpchelper.GetBlockNumber_zkevm(blockNrOrHash, tx, api.filters)
if err != nil {
return nil, err
}
Expand All @@ -395,7 +396,7 @@ func (api *PrivateDebugAPIImpl) GetRawBlock(ctx context.Context, blockNrOrHash r
return nil, err
}
defer tx.Rollback()
n, h, _, err := rpchelper.GetBlockNumber(blockNrOrHash, tx, api.filters)
n, h, _, err := rpchelper.GetBlockNumber_zkevm(blockNrOrHash, tx, api.filters)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions turbo/jsonrpc/erigon_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (api *ErigonImpl) GetHeaderByNumber(ctx context.Context, blockNumber rpc.Bl
}
defer tx.Rollback()

blockNum, _, _, err := rpchelper.GetBlockNumber(rpc.BlockNumberOrHashWithNumber(blockNumber), tx, api.filters)
blockNum, _, _, err := rpchelper.GetBlockNumber_zkevm(rpc.BlockNumberOrHashWithNumber(blockNumber), tx, api.filters)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -213,7 +213,7 @@ func (api *ErigonImpl) GetBalanceChangesInBlock(ctx context.Context, blockNrOrHa
return nil, err
}

blockNumber, _, _, err := rpchelper.GetBlockNumber(blockNrOrHash, tx, api.filters)
blockNumber, _, _, err := rpchelper.GetBlockNumber_zkevm(blockNrOrHash, tx, api.filters)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion turbo/jsonrpc/erigon_receipts.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ func (api *ErigonImpl) GetBlockReceiptsByBlockHash(ctx context.Context, cannonic
}
}

blockNum, _, _, err := rpchelper.GetBlockNumber(rpc.BlockNumberOrHashWithHash(cannonicalBlockHash, true), tx, api.filters)
blockNum, _, _, err := rpchelper.GetBlockNumber_zkevm(rpc.BlockNumberOrHashWithHash(cannonicalBlockHash, true), tx, api.filters)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions turbo/jsonrpc/eth_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func (api *BaseAPI) pendingBlock() *types.Block {
}

func (api *BaseAPI) blockByRPCNumber(ctx context.Context, number rpc.BlockNumber, tx kv.Tx) (*types.Block, error) {
n, h, _, err := rpchelper.GetBlockNumber(rpc.BlockNumberOrHashWithNumber(number), tx, api.filters)
n, h, _, err := rpchelper.GetBlockNumber_zkevm(rpc.BlockNumberOrHashWithNumber(number), tx, api.filters)
if err != nil {
return nil, err
}
Expand All @@ -299,7 +299,7 @@ func (api *BaseAPI) blockByRPCNumber(ctx context.Context, number rpc.BlockNumber
}

func (api *BaseAPI) headerByRPCNumber(ctx context.Context, number rpc.BlockNumber, tx kv.Tx) (*types.Header, error) {
n, h, _, err := rpchelper.GetBlockNumber(rpc.BlockNumberOrHashWithNumber(number), tx, api.filters)
n, h, _, err := rpchelper.GetBlockNumber_zkevm(rpc.BlockNumberOrHashWithNumber(number), tx, api.filters)
if err != nil {
return nil, err
}
Expand All @@ -320,7 +320,7 @@ func (api *BaseAPI) checkPruneHistory(tx kv.Tx, block uint64) error {
return nil
}
if p.History.Enabled() {
latest, _, _, err := rpchelper.GetBlockNumber(rpc.BlockNumberOrHashWithNumber(rpc.LatestBlockNumber), tx, api.filters)
latest, _, _, err := rpchelper.GetBlockNumber_zkevm(rpc.BlockNumberOrHashWithNumber(rpc.LatestBlockNumber), tx, api.filters)
if err != nil {
return err
}
Expand Down
Loading
Loading