Skip to content

Commit 517b563

Browse files
committed
fix(core/genesis): persist upgrade bytes before compat checks
- Also modify Dockerfile to isolate the avalanchego source to not become part of the build context of the main project. - Revert the previous docker related changes.
1 parent a313b3e commit 517b563

File tree

8 files changed

+52
-55
lines changed

8 files changed

+52
-55
lines changed

.dockerignore

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,3 @@
77

88
LICENSE
99
*.md
10-
# Exclude Go test files from Docker build context to prevent test-only code being compiled into images
11-
**/*_test.go
12-
# Safeguard for any stray non-_test helper that could be cached/pulled in CI
13-
network/test_network.go

Dockerfile

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,27 @@ FROM --platform=$BUILDPLATFORM golang:1.24.7-bookworm AS builder
88

99
WORKDIR /build
1010

11-
# Copy avalanche dependencies first (intermediate docker image caching)
12-
# Copy avalanchego directory if present (for manual CI case, which uses local dependency)
13-
COPY go.mod go.sum avalanchego* ./
14-
# Download avalanche dependencies using go mod
15-
RUN go mod download && go mod tidy
11+
# Copy module files first (improves Docker layer caching)
12+
COPY go.mod go.sum ./
13+
# Download module dependencies
14+
RUN go mod download
1615

1716
# Copy the code into the container
1817
COPY . .
1918

19+
# If a local avalanchego source directory is present in the repository (manual CI case),
20+
# move it outside the module root and update the replace directive to point to it so
21+
# avalanchego sources are not flattened into this module's package tree.
22+
RUN if [ -d ./avalanchego ]; then \
23+
mkdir -p /third_party && \
24+
mv ./avalanchego /third_party/avalanchego && \
25+
go mod edit -replace github.com/ava-labs/avalanchego=./third_party/avalanchego && \
26+
go mod tidy; \
27+
fi
28+
2029
# Ensure pre-existing builds are not available for inclusion in the final image
2130
RUN [ -d ./build ] && rm -rf ./build/* || true
2231

23-
2432
ARG TARGETPLATFORM
2533
ARG BUILDPLATFORM
2634

compatibility.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
22
"rpcChainVMProtocolVersion": {
3+
"v0.7.0": 38,
4+
"v0.7.1": 39,
35
"v0.7.10": 43,
4-
"v0.7.9": 43,
5-
"v0.7.8": 43,
6-
"v0.7.7": 42,
7-
"v0.7.6": 42,
8-
"v0.7.5": 41,
9-
"v0.7.4": 40,
10-
"v0.7.3": 39,
116
"v0.7.2": 39,
12-
"v0.7.1": 39,
13-
"v0.7.0": 38
7+
"v0.7.3": 39,
8+
"v0.7.4": 40,
9+
"v0.7.5": 41,
10+
"v0.7.6": 42,
11+
"v0.7.7": 42,
12+
"v0.7.8": 43,
13+
"v0.7.9": 43
1414
}
15-
}
15+
}

core/genesis.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,17 +182,26 @@ func SetupGenesisBlock(
182182
return newcfg, common.Hash{}, err
183183
}
184184

185-
// Read stored config into a local extras copy to avoid mutating shared extras concurrently.
186-
extraCopy := *params.GetExtra(newcfg)
187-
storedcfg := customrawdb.ReadChainConfig(db, stored, &extraCopy)
185+
// Read stored config. We'll persist the new config (including upgrade bytes)
186+
// prior to compatibility checks to ensure on-disk state is up to date.
187+
extra := params.GetExtra(newcfg)
188+
storedcfg := customrawdb.ReadChainConfig(db, stored, extra)
188189
// If there is no previously stored chain config, write the chain config to disk.
189190
if storedcfg == nil {
190191
// Note: this can happen since we did not previously write the genesis block and chain config in the same batch.
191192
log.Warn("Found genesis block without chain config")
192-
customrawdb.WriteChainConfig(db, stored, newcfg, *params.GetExtra(newcfg))
193+
customrawdb.WriteChainConfig(db, stored, newcfg, *extra)
193194
return newcfg, stored, nil
194195
}
195196

197+
// Persist the new chain config (and upgrade bytes) to disk now to avoid
198+
// spurious compatibility failures due to missing upgrade bytes on older databases.
199+
customrawdb.WriteChainConfig(db, stored, newcfg, *extra)
200+
201+
// Re-read stored config into a fresh extras copy for a clean comparison.
202+
storedExtra := *params.GetExtra(newcfg)
203+
storedcfg = customrawdb.ReadChainConfig(db, stored, &storedExtra)
204+
196205
// Notes on the following line:
197206
// - this is needed in coreth to handle the case where existing nodes do not
198207
// have the Berlin or London forks initialized by block number on disk.
@@ -226,9 +235,8 @@ func SetupGenesisBlock(
226235
return newcfg, stored, compatErr
227236
}
228237
}
229-
// Required to write the chain config to disk to ensure both the chain config and upgrade bytes are persisted to disk.
230-
// Note: this intentionally removes an extra check from upstream.
231-
customrawdb.WriteChainConfig(db, stored, newcfg, *params.GetExtra(newcfg))
238+
// Chain config has already been written above.
239+
// Write is idempotent but not required here.
232240
return newcfg, stored, nil
233241
}
234242

network/peer_tracker.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import (
1212
"github.com/ava-labs/avalanchego/utils/set"
1313
"github.com/ava-labs/avalanchego/version"
1414
"github.com/ava-labs/libevm/log"
15+
"github.com/ava-labs/libevm/metrics"
1516

1617
safemath "github.com/ava-labs/avalanchego/utils/math"
17-
evmmetrics "github.com/ava-labs/libevm/metrics" // alias to avoid name collision with local 'metrics' in this package
1818
)
1919

2020
const (
@@ -42,24 +42,24 @@ type peerInfo struct {
4242
// Note: is not thread safe, caller must handle synchronization.
4343
type peerTracker struct {
4444
peers map[ids.NodeID]*peerInfo // all peers we are connected to
45-
numTrackedPeers evmmetrics.Gauge
45+
numTrackedPeers metrics.Gauge
4646
trackedPeers set.Set[ids.NodeID] // peers that we have sent a request to
47-
numResponsivePeers evmmetrics.Gauge
47+
numResponsivePeers metrics.Gauge
4848
responsivePeers set.Set[ids.NodeID] // peers that responded to the last request they were sent
4949
bandwidthHeap safemath.AveragerHeap // tracks bandwidth peers are responding with
50-
averageBandwidthMetric evmmetrics.GaugeFloat64
50+
averageBandwidthMetric metrics.GaugeFloat64
5151
averageBandwidth safemath.Averager
5252
}
5353

5454
func NewPeerTracker() *peerTracker {
5555
return &peerTracker{
5656
peers: make(map[ids.NodeID]*peerInfo),
57-
numTrackedPeers: evmmetrics.GetOrRegisterGauge("net_tracked_peers", nil),
57+
numTrackedPeers: metrics.GetOrRegisterGauge("net_tracked_peers", nil),
5858
trackedPeers: make(set.Set[ids.NodeID]),
59-
numResponsivePeers: evmmetrics.GetOrRegisterGauge("net_responsive_peers", nil),
59+
numResponsivePeers: metrics.GetOrRegisterGauge("net_responsive_peers", nil),
6060
responsivePeers: make(set.Set[ids.NodeID]),
6161
bandwidthHeap: safemath.NewMaxAveragerHeap(),
62-
averageBandwidthMetric: evmmetrics.GetOrRegisterGaugeFloat64("net_average_bandwidth", nil),
62+
averageBandwidthMetric: metrics.GetOrRegisterGaugeFloat64("net_average_bandwidth", nil),
6363
averageBandwidth: safemath.NewAverager(0, bandwidthHalflife, time.Now()),
6464
}
6565
}

network/stats/stats.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package stats
66
import (
77
"time"
88

9-
evmmetrics "github.com/ava-labs/libevm/metrics" // alias to avoid name collision with local 'metrics' in this package
9+
"github.com/ava-labs/libevm/metrics"
1010
)
1111

1212
// RequestHandlerStats provides the interface for metrics for app requests.
@@ -16,8 +16,8 @@ type RequestHandlerStats interface {
1616
}
1717

1818
type requestHandlerStats struct {
19-
timeUntilDeadline evmmetrics.Timer
20-
droppedRequests evmmetrics.Counter
19+
timeUntilDeadline metrics.Timer
20+
droppedRequests metrics.Counter
2121
}
2222

2323
func (h *requestHandlerStats) IncDeadlineDroppedRequest() {
@@ -30,7 +30,7 @@ func (h *requestHandlerStats) UpdateTimeUntilDeadline(duration time.Duration) {
3030

3131
func NewRequestHandlerStats() RequestHandlerStats {
3232
return &requestHandlerStats{
33-
timeUntilDeadline: evmmetrics.GetOrRegisterTimer("net_req_time_until_deadline", nil),
34-
droppedRequests: evmmetrics.GetOrRegisterCounter("net_req_deadline_dropped", nil),
33+
timeUntilDeadline: metrics.GetOrRegisterTimer("net_req_time_until_deadline", nil),
34+
droppedRequests: metrics.GetOrRegisterCounter("net_req_deadline_dropped", nil),
3535
}
3636
}

scripts/build_docker_image.sh

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,6 @@
22

33
set -euo pipefail
44

5-
# If set, ensure a clean git workspace before building to avoid stray files in context
6-
if [[ -n "${CLEAN_CONTEXT:-}" ]]; then
7-
echo "Cleaning build context (git clean -fdx)"
8-
git -C "$(dirname "$0")/.." clean -fdx
9-
fi
10-
11-
# If set, disable build cache for docker buildx
12-
if [[ -n "${NO_CACHE:-}" ]]; then
13-
DOCKER_NO_CACHE="--no-cache"
14-
else
15-
DOCKER_NO_CACHE=""
16-
fi
17-
185
# If set to non-empty, prompts the building of a multi-arch image when the image
196
# name indicates use of a registry.
207
#
@@ -47,7 +34,7 @@ ALLOW_TAG_LATEST="${ALLOW_TAG_LATEST:-}"
4734
# simplifies creation of multi-arch images.
4835
#
4936
# Reference: https://docs.docker.com/build/buildkit/
50-
DOCKER_CMD="docker buildx build ${DOCKER_NO_CACHE}"
37+
DOCKER_CMD="docker buildx build"
5138
ispush=0
5239
if [[ -n "${PUBLISH}" ]]; then
5340
echo "Pushing $IMAGE_NAME:$BUILD_IMAGE_ID"

scripts/tests.build_docker_image.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ build_and_test() {
3636
VM_ID=$"${vm_id}" \
3737
IMAGE_NAME="${imagename}" \
3838
AVALANCHEGO_LOCAL_IMAGE_NAME="${avalanchego_local_image_name}" \
39-
CLEAN_CONTEXT=1 \
40-
NO_CACHE=1 \
4139
./scripts/build_docker_image.sh
4240

4341
echo "listing images"

0 commit comments

Comments
 (0)