mirror of
https://github.com/luxfi/evm.git
synced 2026-09-24 00:27:44 +00:00
Update to latest geth, so on
This commit is contained in:
@@ -0,0 +1,248 @@
|
||||
# Subnet EVM Makefile
|
||||
|
||||
# Root directory
|
||||
EVM_PATH := $(shell pwd)
|
||||
|
||||
# Load constants - these will be set via shell commands
|
||||
GOPATH := $(shell go env GOPATH)
|
||||
DEFAULT_PLUGIN_DIR := $(HOME)/.luxd/plugins
|
||||
DEFAULT_VM_NAME := evm
|
||||
DEFAULT_VM_ID := srEXiWaHuhNyGwPUi444Tu47ZEDwxTWrbQiuD7FmgSAQ6X7Dy
|
||||
|
||||
# Git commit
|
||||
EVM_COMMIT := $(shell git rev-parse HEAD 2>/dev/null || echo "unknown")
|
||||
CURRENT_BRANCH := $(shell git describe --tags --exact-match 2>/dev/null || git symbolic-ref -q --short HEAD || git rev-parse --short HEAD || echo "unknown")
|
||||
|
||||
# Lux version from go.mod
|
||||
LUX_VERSION := $(shell go list -m github.com/luxfi/luxd 2>/dev/null | awk '{print $$2}')
|
||||
|
||||
# Build flags
|
||||
LDFLAGS := -X github.com/luxfi/evm/plugin/evm.GitCommit=$(EVM_COMMIT)
|
||||
STATIC_LD_FLAGS :=
|
||||
CGO_ENABLED := 1
|
||||
CGO_CFLAGS := -O2 -D__BLST_PORTABLE__
|
||||
|
||||
# Binary path
|
||||
BINARY_PATH := $(DEFAULT_PLUGIN_DIR)/$(DEFAULT_VM_ID)
|
||||
|
||||
# Export necessary variables
|
||||
export CGO_ENABLED
|
||||
export CGO_CFLAGS
|
||||
|
||||
.PHONY: all build clean test lint install setup generate help
|
||||
|
||||
# Default target
|
||||
all: build
|
||||
|
||||
# Help target
|
||||
help:
|
||||
@echo "Subnet EVM Makefile"
|
||||
@echo ""
|
||||
@echo "Usage:"
|
||||
@echo " make [target]"
|
||||
@echo ""
|
||||
@echo "Targets:"
|
||||
@echo " all Build Subnet EVM (default)"
|
||||
@echo " build Build Subnet EVM binary"
|
||||
@echo " install Build and install to default plugin directory"
|
||||
@echo " clean Clean build artifacts"
|
||||
@echo " test Run all tests"
|
||||
@echo " test-unit Run unit tests"
|
||||
@echo " test-e2e Run end-to-end tests"
|
||||
@echo " lint Run linters"
|
||||
@echo " lint-all Run all lint checks"
|
||||
@echo " generate Generate code (mocks, codecs)"
|
||||
@echo " setup Setup development environment"
|
||||
@echo " docker Build Docker image"
|
||||
@echo " check-version Check luxd version"
|
||||
@echo ""
|
||||
@echo "Build options:"
|
||||
@echo " BINARY_PATH Set custom binary output path (default: $(BINARY_PATH))"
|
||||
@echo " STATIC_COMPILATION=1 Enable static compilation"
|
||||
|
||||
# Build the Subnet EVM binary
|
||||
build: ensure-deps
|
||||
@echo "Building Subnet EVM @ GitCommit: $(EVM_COMMIT)"
|
||||
go build -ldflags "$(LDFLAGS) $(STATIC_LD_FLAGS)" -o bin/$(DEFAULT_VM_ID) ./plugin/*.go
|
||||
|
||||
# Ensure dependencies are in place
|
||||
ensure-deps:
|
||||
@echo "Checking dependencies..."
|
||||
@if [ ! -f go.sum ]; then \
|
||||
echo "go.sum missing, running go mod download..."; \
|
||||
go mod download; \
|
||||
fi
|
||||
|
||||
# Fix dependencies - download missing modules and generate go.sum
|
||||
fix-deps:
|
||||
@echo "Fixing dependencies..."
|
||||
@echo "Downloading modules..."
|
||||
go mod download
|
||||
@echo "Dependencies fixed."
|
||||
|
||||
# Build with custom output path
|
||||
build-custom:
|
||||
@echo "Building Subnet EVM @ GitCommit: $(EVM_COMMIT) at $(BINARY_PATH)"
|
||||
go build -ldflags "$(LDFLAGS) $(STATIC_LD_FLAGS)" -o "$(BINARY_PATH)" ./plugin/*.go
|
||||
|
||||
# Install to default plugin directory
|
||||
install: build
|
||||
@echo "Installing Subnet EVM to $(DEFAULT_PLUGIN_DIR)"
|
||||
@mkdir -p $(DEFAULT_PLUGIN_DIR)
|
||||
@cp bin/$(DEFAULT_VM_ID) $(DEFAULT_PLUGIN_DIR)/
|
||||
|
||||
# Clean build artifacts
|
||||
clean:
|
||||
@echo "Cleaning build artifacts..."
|
||||
@rm -rf bin/
|
||||
@rm -f $(DEFAULT_PLUGIN_DIR)/$(DEFAULT_VM_ID)
|
||||
@go clean -cache
|
||||
|
||||
# Run all tests
|
||||
test:
|
||||
@echo "Running all tests..."
|
||||
./scripts/build_test.sh
|
||||
|
||||
# Run unit tests only
|
||||
test-unit:
|
||||
@echo "Running unit tests..."
|
||||
go test -v -timeout=30m ./...
|
||||
|
||||
# Run unit tests with race detection
|
||||
test-race:
|
||||
@echo "Running tests with race detection..."
|
||||
go test -v -race -timeout=30m ./...
|
||||
|
||||
# Run E2E tests
|
||||
test-e2e: test-e2e-precompile test-e2e-load test-e2e-warp
|
||||
|
||||
test-e2e-precompile:
|
||||
@echo "Running E2E precompile tests..."
|
||||
./scripts/run_ginkgo_precompile.sh
|
||||
|
||||
test-e2e-load:
|
||||
@echo "Running E2E load tests..."
|
||||
./scripts/run_ginkgo_load.sh
|
||||
|
||||
test-e2e-warp:
|
||||
@echo "Running E2E warp tests..."
|
||||
./scripts/run_ginkgo_warp.sh
|
||||
|
||||
# Benchmarks
|
||||
bench:
|
||||
@echo "Running benchmarks..."
|
||||
./scripts/build_bench_precompiles.sh
|
||||
|
||||
# Coverage
|
||||
coverage:
|
||||
@echo "Generating coverage report..."
|
||||
go test -v -coverprofile=coverage.out ./...
|
||||
./scripts/coverage.sh
|
||||
|
||||
# Linting
|
||||
lint:
|
||||
@echo "Running linters..."
|
||||
./scripts/lint.sh
|
||||
|
||||
lint-all:
|
||||
@echo "Running all lint checks..."
|
||||
@$(MAKE) lint
|
||||
@./scripts/actionlint.sh
|
||||
@./scripts/shellcheck.sh
|
||||
@$(MAKE) check-generate
|
||||
|
||||
# Code generation
|
||||
generate: generate-mocks generate-codec
|
||||
|
||||
generate-mocks:
|
||||
@echo "Generating mocks..."
|
||||
@grep -lr -E '^// Code generated by MockGen\. DO NOT EDIT\.' . | xargs -r rm
|
||||
@go generate -run "go.uber.org/mock/mockgen" ./...
|
||||
|
||||
generate-codec:
|
||||
@echo "Generating codec..."
|
||||
@grep -lr -E '^// Code generated by github\.com\/fjl\/gencodec\. DO NOT EDIT\.' . | xargs -r rm
|
||||
@go generate -run "github.com/fjl/gencodec" ./...
|
||||
|
||||
# Check if generated files are up to date
|
||||
check-generate: generate
|
||||
@echo "Checking if generated files are up to date..."
|
||||
@git diff --exit-code || (echo "Generated files are out of date. Please run 'make generate'." && exit 1)
|
||||
|
||||
# Setup development environment
|
||||
setup:
|
||||
@echo "Setting up development environment..."
|
||||
@echo "Installing dependencies..."
|
||||
go mod download
|
||||
@echo "Installing tools..."
|
||||
go install -v github.com/fjl/gencodec@latest
|
||||
go install -v go.uber.org/mock/mockgen@latest
|
||||
@echo "Setting up contracts..."
|
||||
cd contracts && npm ci && npx hardhat clean && npx hardhat compile
|
||||
|
||||
# Docker image
|
||||
docker:
|
||||
@echo "Building Docker image..."
|
||||
./scripts/build_docker_image.sh
|
||||
|
||||
docker-test:
|
||||
@echo "Testing Docker image build..."
|
||||
./scripts/tests.build_docker_image.sh
|
||||
|
||||
# Version management
|
||||
check-version:
|
||||
@echo "Checking luxd version..."
|
||||
@echo "Current luxd version: $(LUX_VERSION)"
|
||||
./scripts/update_luxd_version.sh
|
||||
|
||||
# Install luxd for testing
|
||||
install-luxd:
|
||||
@echo "Installing luxd..."
|
||||
./scripts/install_luxd_release.sh
|
||||
|
||||
# Development helpers
|
||||
dev-shell:
|
||||
@echo "Starting development shell..."
|
||||
./scripts/dev_shell.sh
|
||||
|
||||
# Run local node for testing
|
||||
run-local: build
|
||||
@echo "Running local node..."
|
||||
./scripts/run.sh
|
||||
|
||||
# Format code
|
||||
fmt:
|
||||
@echo "Formatting Go code..."
|
||||
go fmt ./...
|
||||
gofmt -s -w .
|
||||
|
||||
# Check go mod tidy
|
||||
check-go-mod:
|
||||
@echo "Checking go.mod..."
|
||||
go mod tidy
|
||||
@git diff --exit-code go.mod go.sum || (echo "go.mod or go.sum is out of date. Please run 'go mod tidy'." && exit 1)
|
||||
|
||||
# Run simulator
|
||||
simulator: build
|
||||
@echo "Running simulator..."
|
||||
./scripts/run_simulator.sh
|
||||
|
||||
# Antithesis testing
|
||||
antithesis-images:
|
||||
@echo "Building Antithesis images..."
|
||||
./scripts/build_antithesis_images.sh
|
||||
|
||||
test-antithesis: install-luxd build
|
||||
@echo "Running Antithesis tests..."
|
||||
go run ./tests/antithesis --luxd-path=/tmp/e2e-test/luxd/luxd --duration=60s
|
||||
|
||||
# Quick build for development
|
||||
dev: build
|
||||
|
||||
# Full CI pipeline
|
||||
ci: check-go-mod lint-all test coverage
|
||||
|
||||
.PHONY: build-custom test-unit test-race test-e2e test-e2e-precompile test-e2e-load test-e2e-warp
|
||||
.PHONY: bench coverage generate-mocks generate-codec check-generate setup docker docker-test
|
||||
.PHONY: check-version install-luxd dev-shell run-local fmt check-go-mod simulator
|
||||
.PHONY: antithesis-images test-antithesis dev ci
|
||||
@@ -68,7 +68,7 @@ build/Release
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Snowpack dependency directory (https://snowpack.dev/)
|
||||
# Consensuspack dependency directory (https://consensuspack.dev/)
|
||||
web_modules/
|
||||
|
||||
# TypeScript cache
|
||||
|
||||
@@ -41,7 +41,7 @@ interface IWarpMessenger {
|
||||
uint32 index
|
||||
) external view returns (WarpBlockHash calldata warpBlockHash, bool valid);
|
||||
|
||||
// getBlockchainID returns the snow.Context BlockchainID of this chain.
|
||||
// getBlockchainID returns the consensus.Context BlockchainID of this chain.
|
||||
// This blockchainID is the hash of the transaction that created this blockchain on the P-Chain
|
||||
// and is not related to the Ethereum ChainID.
|
||||
function getBlockchainID() external view returns (bytes32 blockchainID);
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/luxfi/geth/core/types"
|
||||
"github.com/luxfi/geth/core/vm"
|
||||
"github.com/luxfi/evm/params"
|
||||
"github.com/luxfi/evm/predicate"
|
||||
)
|
||||
|
||||
type VmStateDB interface {
|
||||
@@ -37,12 +38,18 @@ func New(vm VmStateDB) *StateDB {
|
||||
}
|
||||
|
||||
func (s *StateDB) Prepare(rules params.Rules, sender, coinbase common.Address, dst *common.Address, precompiles []common.Address, list types.AccessList) {
|
||||
// For now, we'll skip predicate storage slots preparation
|
||||
// TODO: Integrate with extras.Rules when available
|
||||
// Note: This method cannot access extras.Rules directly without chainConfig and timestamp
|
||||
// Predicate storage slots will be empty unless PrepareWithExtrasRules is used
|
||||
s.predicateStorageSlots = make(map[common.Address][][]byte)
|
||||
s.vmStateDB.Prepare(rules, sender, coinbase, dst, precompiles, list)
|
||||
}
|
||||
|
||||
// PrepareWithExtrasRules prepares the state with extras.Rules for predicate support
|
||||
func (s *StateDB) PrepareWithExtrasRules(rules params.Rules, extrasRules predicate.PredicaterExistChecker, sender, coinbase common.Address, dst *common.Address, precompiles []common.Address, list types.AccessList) {
|
||||
s.predicateStorageSlots = predicate.PreparePredicateStorageSlots(extrasRules, list)
|
||||
s.vmStateDB.Prepare(rules, sender, coinbase, dst, precompiles, list)
|
||||
}
|
||||
|
||||
// GetPredicateStorageSlots returns the storage slots associated with the address, index pair.
|
||||
// A list of access tuples can be included within transaction types post EIP-2930. The address
|
||||
// is declared directly on the access tuple and the index is the i'th occurrence of an access
|
||||
|
||||
+51
-2
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/luxfi/geth/core/types"
|
||||
"github.com/luxfi/geth/log"
|
||||
"github.com/luxfi/evm/params"
|
||||
"github.com/luxfi/evm/params/extras"
|
||||
"github.com/luxfi/evm/precompile/precompileconfig"
|
||||
"github.com/luxfi/evm/predicate"
|
||||
)
|
||||
@@ -30,8 +31,56 @@ func CheckPredicates(rules params.Rules, predicateContext *precompileconfig.Pred
|
||||
return nil, fmt.Errorf("%w for predicate verification (%d) < intrinsic gas (%d)", ErrIntrinsicGas, tx.Gas(), intrinsicGas)
|
||||
}
|
||||
|
||||
// TODO: Properly integrate predicates with extras.Rules
|
||||
// For now, return empty predicate results
|
||||
// This version cannot access extras.Rules without chainConfig and timestamp
|
||||
// Use CheckPredicatesWithRules for full predicate support
|
||||
predicateResults := make(map[common.Address][]byte)
|
||||
return predicateResults, nil
|
||||
}
|
||||
|
||||
// CheckPredicatesWithRules verifies the predicates of [tx] with full extras.Rules support
|
||||
func CheckPredicatesWithRules(rules params.Rules, extrasRules *extras.Rules, predicateContext *precompileconfig.PredicateContext, tx *types.Transaction) (map[common.Address][]byte, error) {
|
||||
// Check that the transaction can cover its IntrinsicGas (including the gas required by the predicate) before
|
||||
// verifying the predicate.
|
||||
intrinsicGas, err := IntrinsicGas(tx.Data(), tx.AccessList(), tx.To() == nil, rules)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if tx.Gas() < intrinsicGas {
|
||||
return nil, fmt.Errorf("%w for predicate verification (%d) < intrinsic gas (%d)", ErrIntrinsicGas, tx.Gas(), intrinsicGas)
|
||||
}
|
||||
|
||||
predicateResults := make(map[common.Address][]byte)
|
||||
// Short circuit early if there are no precompile predicates to verify
|
||||
if !extrasRules.PredicatersExist() {
|
||||
return predicateResults, nil
|
||||
}
|
||||
|
||||
// Prepare the predicate storage slots from the transaction's access list
|
||||
predicateArguments := predicate.PreparePredicateStorageSlots(extrasRules, tx.AccessList())
|
||||
|
||||
// If there are no predicates to verify, return early and skip requiring the proposervm block
|
||||
// context to be populated.
|
||||
if len(predicateArguments) == 0 {
|
||||
return predicateResults, nil
|
||||
}
|
||||
|
||||
if predicateContext == nil || predicateContext.ProposerVMBlockCtx == nil {
|
||||
return nil, ErrMissingPredicateContext
|
||||
}
|
||||
|
||||
for address, predicates := range predicateArguments {
|
||||
// Since [address] is only added to [predicateArguments] when there's a valid predicate in the ruleset
|
||||
// there's no need to check if the predicate exists here.
|
||||
predicaterContract := extrasRules.Predicaters[address]
|
||||
bitset := set.NewBits()
|
||||
for i, predicate := range predicates {
|
||||
if err := predicaterContract.VerifyPredicate(predicateContext, predicate); err != nil {
|
||||
bitset.Add(i)
|
||||
}
|
||||
}
|
||||
res := bitset.Bytes()
|
||||
log.Debug("predicate verify", "tx", tx.Hash(), "address", address, "res", res)
|
||||
predicateResults[address] = res
|
||||
}
|
||||
return predicateResults, nil
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ func newBlobTxMeta(id uint64, size uint32, tx *types.Transaction) *blobTxMeta {
|
||||
|
||||
// BlobPool is the transaction pool dedicated to EIP-4844 blob transactions.
|
||||
//
|
||||
// Blob transactions are special snowflakes that are designed for a very specific
|
||||
// Blob transactions are special consensusflakes that are designed for a very specific
|
||||
// purpose (rollups) and are expected to adhere to that specific use case. These
|
||||
// behavioural expectations allow us to design a transaction pool that is more robust
|
||||
// (i.e. resending issues) and more resilient to DoS attacks (e.g. replace-flush
|
||||
|
||||
+1
-1
@@ -205,7 +205,7 @@ func New(
|
||||
|
||||
// If the context is not set, avoid a panic. Only necessary during firewood use.
|
||||
chainDataDir := ""
|
||||
if ctx := params.GetExtra(config.Genesis.Config).SnowCtx; ctx != nil {
|
||||
if ctx := params.GetExtra(config.Genesis.Config).ConsensusCtx; ctx != nil {
|
||||
chainDataDir = ctx.ChainDataDir
|
||||
}
|
||||
|
||||
|
||||
@@ -2,10 +2,6 @@ module github.com/luxfi/evm
|
||||
|
||||
go 1.24.5
|
||||
|
||||
replace (
|
||||
github.com/luxfi/geth => github.com/luxfi/geth v1.16.1
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/VictoriaMetrics/fastcache v1.12.5
|
||||
github.com/antithesishq/antithesis-sdk-go v0.3.8
|
||||
@@ -22,7 +18,7 @@ require (
|
||||
github.com/holiman/uint256 v1.3.2
|
||||
github.com/luxfi/crypto v1.2.1
|
||||
github.com/luxfi/database v1.1.7
|
||||
github.com/luxfi/geth v1.16.24
|
||||
github.com/luxfi/geth v1.16.2
|
||||
github.com/luxfi/go-bip39 v1.1.0
|
||||
github.com/luxfi/ids v1.0.2
|
||||
github.com/luxfi/metrics v1.1.1
|
||||
@@ -51,6 +47,14 @@ require (
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1
|
||||
)
|
||||
|
||||
replace (
|
||||
github.com/gojuukaze/go-bip39 => github.com/luxfi/go-bip39 v1.1.0
|
||||
github.com/luxfi/database => ../database
|
||||
github.com/luxfi/geth => ../geth
|
||||
github.com/luxfi/go-bip39 => ../go-bip39
|
||||
github.com/luxfi/node => ../node
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/DataDog/zstd v1.5.7 // indirect
|
||||
github.com/Microsoft/go-winio v0.6.2 // indirect
|
||||
@@ -84,7 +88,6 @@ require (
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/emicklei/dot v1.6.2 // indirect
|
||||
github.com/ethereum/c-kzg-4844/v2 v2.1.1 // indirect
|
||||
github.com/luxfi/geth v1.16.1 // indirect
|
||||
github.com/ethereum/go-verkle v0.2.2 // indirect
|
||||
github.com/ferranbt/fastssz v0.1.4 // indirect
|
||||
github.com/fsnotify/fsnotify v1.8.0 // indirect
|
||||
|
||||
@@ -116,8 +116,6 @@ github.com/emicklei/dot v1.6.2 h1:08GN+DD79cy/tzN6uLCT84+2Wk9u+wvqP+Hkx/dIR8A=
|
||||
github.com/emicklei/dot v1.6.2/go.mod h1:DeV7GvQtIw4h2u73RKBkkFdvVAz0D9fzeJrgPW6gy/s=
|
||||
github.com/ethereum/c-kzg-4844/v2 v2.1.1 h1:KhzBVjmURsfr1+S3k/VE35T02+AW2qU9t9gr4R6YpSo=
|
||||
github.com/ethereum/c-kzg-4844/v2 v2.1.1/go.mod h1:TC48kOKjJKPbN7C++qIgt0TJzZ70QznYR7Ob+WXl57E=
|
||||
github.com/ethereum/go-ethereum v1.16.1 h1:7684NfKCb1+IChudzdKyZJ12l1Tq4ybPZOITiCDXqCk=
|
||||
github.com/ethereum/go-ethereum v1.16.1/go.mod h1:ngYIvmMAYdo4sGW9cGzLvSsPGhDOOzL0jK5S5iXpj0g=
|
||||
github.com/ethereum/go-verkle v0.2.2 h1:I2W0WjnrFUIzzVPwm8ykY+7pL2d4VhlsePn4j7cnFk8=
|
||||
github.com/ethereum/go-verkle v0.2.2/go.mod h1:M3b90YRnzqKyyzBEWJGqj8Qff4IDeXnzFw0P9bFw3uk=
|
||||
github.com/ferranbt/fastssz v0.1.4 h1:OCDB+dYDEQDvAgtAGnTSidK1Pe2tW3nFV40XyMkTeDY=
|
||||
@@ -253,20 +251,12 @@ github.com/leanovate/gopter v0.2.11 h1:vRjThO1EKPb/1NsDXuDrzldR28RLkBflWYcU9CvzW
|
||||
github.com/leanovate/gopter v0.2.11/go.mod h1:aK3tzZP/C+p1m3SPRE4SYZFGP7jjkuSI4f7Xvpt0S9c=
|
||||
github.com/luxfi/crypto v1.2.1 h1:9QlSJFJcxz14b7sBLTaxKI6My0Rzy4DJT7JSS9WlZlU=
|
||||
github.com/luxfi/crypto v1.2.1/go.mod h1:qIfHGq5kzTUqzyTqj6II5/6aEp0OWntfeOdhYy/d7aQ=
|
||||
github.com/luxfi/database v1.1.7 h1:sskVC0lL5HMELmklQGHnGBlYYD6n+kWGls4XDxye/tg=
|
||||
github.com/luxfi/database v1.1.7/go.mod h1:0uBGc+U7415yAKBjImaz+OkGzeFaqxH3pcgB3pmofjM=
|
||||
github.com/luxfi/geth v1.16.1 h1:f6kUUuj1vnIwk7rbyDH0py51p6O7uxitNEPUDaeEYNI=
|
||||
github.com/luxfi/geth v1.16.1/go.mod h1:oW6L657BBT0okG+yQaBzuzg5XZ38RLdKupHyKf17LAc=
|
||||
github.com/luxfi/go-bip39 v1.1.0 h1:5ZNX8E5+8tOYRy+G2Yp2msiRwHWEM6hzq9HpM8ZgsIg=
|
||||
github.com/luxfi/go-bip39 v1.1.0/go.mod h1:OxPL7QXUfnqqk7nOTPWgNfShxqg69OYJ4+ATKCmZWP8=
|
||||
github.com/luxfi/ids v1.0.2 h1:OnbCWBgdmuBPZat1r1vRikk1FFrdHMfSknpfKmX0KBg=
|
||||
github.com/luxfi/ids v1.0.2/go.mod h1:cMbto3Q8N3IaBxdz4Lzaq9wYl33coGXUdlr2+YwXeUw=
|
||||
github.com/luxfi/log v0.1.1 h1:KRTOIGqyPTrN3nWcBMVI50B6EXTayYex2+HyGjJ06Ew=
|
||||
github.com/luxfi/log v0.1.1/go.mod h1:trb99HbI+YW6nu+So4jWKey20oHeRhlee70xbuR6Gak=
|
||||
github.com/luxfi/metrics v1.1.1 h1:aKVEtytAl3TqSvInRpDc6ZdSJsCbTmCCl0UAl2YNXWU=
|
||||
github.com/luxfi/metrics v1.1.1/go.mod h1:ynSRcRjG+t1snUvFUbQFEu0UGibyw8gsitltQ9H1YDA=
|
||||
github.com/luxfi/node v1.13.4 h1:tbBL+9L8NLZtrCATdqvc63K5HLaUjDJetoDGPmV/8lU=
|
||||
github.com/luxfi/node v1.13.4/go.mod h1:RD6RGOsc8KYH1HMSuQuVqjMkPd4Td2Zib4EUjUHe1qU=
|
||||
github.com/luxfi/trace v0.1.1 h1:T/ReB1MvwAJpgQaPWGsBLUx96rr5OMlJocWRo5JSvkU=
|
||||
github.com/luxfi/trace v0.1.1/go.mod h1:6jhCW0hPCFv7qzFsL0w/amHRv7PfNIyW77N4WDS3U5Q=
|
||||
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
|
||||
"github.com/luxfi/node/codec"
|
||||
"github.com/luxfi/node/ids"
|
||||
"github.com/luxfi/ids"
|
||||
"github.com/luxfi/node/network/p2p"
|
||||
"github.com/luxfi/node/consensus"
|
||||
"github.com/luxfi/node/consensus/engine/core"
|
||||
|
||||
+14
-14
@@ -53,7 +53,7 @@ var (
|
||||
)
|
||||
|
||||
func TestNetworkDoesNotConnectToItself(t *testing.T) {
|
||||
ctx := snowtest.Context(t, snowtest.CChainID)
|
||||
ctx := consensustest.Context(t, consensustest.CChainID)
|
||||
n, err := NewNetwork(ctx, nil, nil, 1, prometheus.NewRegistry())
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, n.Connected(context.Background(), ctx.NodeID, defaultPeerVersion))
|
||||
@@ -90,7 +90,7 @@ func TestRequestAnyRequestsRoutingAndResponse(t *testing.T) {
|
||||
}
|
||||
|
||||
codecManager := buildCodec(t, HelloRequest{}, HelloResponse{})
|
||||
ctx := snowtest.Context(t, snowtest.CChainID)
|
||||
ctx := consensustest.Context(t, consensustest.CChainID)
|
||||
net, err := NewNetwork(ctx, sender, codecManager, 16, prometheus.NewRegistry())
|
||||
require.NoError(t, err)
|
||||
net.SetRequestHandler(&HelloGreetingRequestHandler{codec: codecManager})
|
||||
@@ -141,8 +141,8 @@ func TestAppRequestOnCtxCancellation(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
snowCtx := snowtest.Context(t, snowtest.CChainID)
|
||||
net, err := NewNetwork(snowCtx, sender, codecManager, 1, prometheus.NewRegistry())
|
||||
consensusCtx := consensustest.Context(t, consensustest.CChainID)
|
||||
net, err := NewNetwork(consensusCtx, sender, codecManager, 1, prometheus.NewRegistry())
|
||||
require.NoError(t, err)
|
||||
handler := &HelloGreetingRequestHandler{codec: codecManager}
|
||||
net.SetRequestHandler(handler)
|
||||
@@ -194,7 +194,7 @@ func TestRequestRequestsRoutingAndResponse(t *testing.T) {
|
||||
}
|
||||
|
||||
codecManager := buildCodec(t, HelloRequest{}, HelloResponse{})
|
||||
ctx := snowtest.Context(t, snowtest.CChainID)
|
||||
ctx := consensustest.Context(t, consensustest.CChainID)
|
||||
net, err := NewNetwork(ctx, sender, codecManager, 16, prometheus.NewRegistry())
|
||||
require.NoError(t, err)
|
||||
net.SetRequestHandler(&HelloGreetingRequestHandler{codec: codecManager})
|
||||
@@ -275,7 +275,7 @@ func TestAppRequestOnShutdown(t *testing.T) {
|
||||
}
|
||||
|
||||
codecManager := buildCodec(t, HelloRequest{}, HelloResponse{})
|
||||
ctx := snowtest.Context(t, snowtest.CChainID)
|
||||
ctx := consensustest.Context(t, consensustest.CChainID)
|
||||
net, err := NewNetwork(ctx, sender, codecManager, 1, prometheus.NewRegistry())
|
||||
require.NoError(t, err)
|
||||
nodeID := ids.GenerateTestNodeID()
|
||||
@@ -323,8 +323,8 @@ func TestSyncedAppRequestAnyOnCtxCancellation(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
snowCtx := snowtest.Context(t, snowtest.CChainID)
|
||||
net, err := NewNetwork(snowCtx, sender, codecManager, 1, prometheus.NewRegistry())
|
||||
consensusCtx := consensustest.Context(t, consensustest.CChainID)
|
||||
net, err := NewNetwork(consensusCtx, sender, codecManager, 1, prometheus.NewRegistry())
|
||||
require.NoError(t, err)
|
||||
net.SetRequestHandler(&HelloGreetingRequestHandler{codec: codecManager})
|
||||
assert.NoError(t,
|
||||
@@ -398,7 +398,7 @@ func TestRequestMinVersion(t *testing.T) {
|
||||
}
|
||||
|
||||
// passing nil as codec works because the net.AppRequest is never called
|
||||
ctx := snowtest.Context(t, snowtest.CChainID)
|
||||
ctx := consensustest.Context(t, consensustest.CChainID)
|
||||
net, err := NewNetwork(ctx, sender, codecManager, 1, prometheus.NewRegistry())
|
||||
require.NoError(t, err)
|
||||
requestMessage := TestMessage{Message: "this is a request"}
|
||||
@@ -463,7 +463,7 @@ func TestOnRequestHonoursDeadline(t *testing.T) {
|
||||
processingDuration: 500 * time.Millisecond,
|
||||
}
|
||||
|
||||
ctx := snowtest.Context(t, snowtest.CChainID)
|
||||
ctx := consensustest.Context(t, consensustest.CChainID)
|
||||
net, err = NewNetwork(ctx, sender, codecManager, 1, prometheus.NewRegistry())
|
||||
require.NoError(t, err)
|
||||
net.SetRequestHandler(requestHandler)
|
||||
@@ -491,7 +491,7 @@ func TestHandleInvalidMessages(t *testing.T) {
|
||||
return nil
|
||||
},
|
||||
}
|
||||
ctx := snowtest.Context(t, snowtest.CChainID)
|
||||
ctx := consensustest.Context(t, consensustest.CChainID)
|
||||
clientNetwork, err := NewNetwork(ctx, sender, codecManager, 1, prometheus.NewRegistry())
|
||||
require.NoError(t, err)
|
||||
clientNetwork.SetRequestHandler(&testRequestHandler{})
|
||||
@@ -540,7 +540,7 @@ func TestNetworkPropagatesRequestHandlerError(t *testing.T) {
|
||||
requestID := peertest.TestPeerRequestID
|
||||
sender := testAppSender{}
|
||||
|
||||
ctx := snowtest.Context(t, snowtest.CChainID)
|
||||
ctx := consensustest.Context(t, consensustest.CChainID)
|
||||
clientNetwork, err := NewNetwork(ctx, sender, codecManager, 1, prometheus.NewRegistry())
|
||||
require.NoError(t, err)
|
||||
clientNetwork.SetRequestHandler(&testRequestHandler{err: errors.New("fail")}) // Return an error from the request handler
|
||||
@@ -560,7 +560,7 @@ func TestNetworkPropagatesRequestHandlerError(t *testing.T) {
|
||||
func TestNetworkAppRequestAfterShutdown(t *testing.T) {
|
||||
require := require.New(t)
|
||||
|
||||
ctx := snowtest.Context(t, snowtest.CChainID)
|
||||
ctx := consensustest.Context(t, consensustest.CChainID)
|
||||
net, err := NewNetwork(ctx, nil, nil, 16, prometheus.NewRegistry())
|
||||
require.NoError(err)
|
||||
net.Shutdown()
|
||||
@@ -584,7 +584,7 @@ func TestNetworkRouting(t *testing.T) {
|
||||
handler := &testSDKHandler{}
|
||||
|
||||
networkCodec := codec.NewManager(0)
|
||||
ctx := snowtest.Context(t, snowtest.CChainID)
|
||||
ctx := consensustest.Context(t, consensustest.CChainID)
|
||||
network, err := NewNetwork(ctx, sender, networkCodec, 1, prometheus.NewRegistry())
|
||||
require.NoError(err)
|
||||
require.NoError(network.AddHandler(uint64(protocol), handler))
|
||||
|
||||
+80
-1
@@ -12,6 +12,8 @@ import (
|
||||
"github.com/luxfi/geth/common"
|
||||
"github.com/luxfi/node/upgrade"
|
||||
"github.com/luxfi/evm/params/extras"
|
||||
"github.com/luxfi/evm/precompile/modules"
|
||||
"github.com/luxfi/evm/precompile/precompileconfig"
|
||||
"github.com/luxfi/evm/utils"
|
||||
)
|
||||
|
||||
@@ -36,6 +38,18 @@ var (
|
||||
chainConfigMutex sync.RWMutex
|
||||
)
|
||||
|
||||
// getPrecompileAddress returns the address for a precompile config
|
||||
func getPrecompileAddress(config precompileconfig.Config) common.Address {
|
||||
// Get all registered modules
|
||||
for _, module := range modules.RegisteredModules() {
|
||||
// Match by config key
|
||||
if module.ConfigKey == config.Key() {
|
||||
return module.Address
|
||||
}
|
||||
}
|
||||
return common.Address{}
|
||||
}
|
||||
|
||||
// RulesExtra represents extra EVM rules - part of libevm integration
|
||||
type RulesExtra struct {
|
||||
IsSubnetEVM bool
|
||||
@@ -204,7 +218,7 @@ func ToWithUpgradesJSON(c *ChainConfig) *ChainConfigWithUpgradesJSON {
|
||||
|
||||
func SetNetworkUpgradeDefaults(c *ChainConfig) {
|
||||
// TODO: NetworkUpgrades field not available in current consensus.Context
|
||||
// GetExtra(c).NetworkUpgrades.SetDefaults(GetExtra(c).SnowCtx.NetworkUpgrades)
|
||||
// GetExtra(c).NetworkUpgrades.SetDefaults(GetExtra(c).ConsensusCtx.NetworkUpgrades)
|
||||
// For now, set empty defaults with empty upgrade config
|
||||
emptyUpgradeConfig := upgrade.Config{}
|
||||
GetExtra(c).NetworkUpgrades.SetDefaults(emptyUpgradeConfig)
|
||||
@@ -217,3 +231,68 @@ func GetRulesExtra(rules Rules) RulesExtra {
|
||||
IsSubnetEVM: true, // Default to true for SubnetEVM
|
||||
}
|
||||
}
|
||||
|
||||
// GetExtrasRules returns the extras.Rules for the given params.Rules and timestamp
|
||||
func GetExtrasRules(ethRules Rules, c *ChainConfig, timestamp uint64) *extras.Rules {
|
||||
if c == nil {
|
||||
return &extras.Rules{
|
||||
LuxRules: extras.LuxRules{},
|
||||
Precompiles: make(map[common.Address]precompileconfig.Config),
|
||||
Predicaters: make(map[common.Address]precompileconfig.Predicater),
|
||||
AccepterPrecompiles: make(map[common.Address]precompileconfig.Accepter),
|
||||
}
|
||||
}
|
||||
|
||||
extra := GetExtra(c)
|
||||
luxRules := extra.NetworkUpgrades.GetLuxRules(timestamp)
|
||||
|
||||
// Build extras.Rules
|
||||
rules := &extras.Rules{
|
||||
LuxRules: luxRules,
|
||||
Precompiles: make(map[common.Address]precompileconfig.Config),
|
||||
Predicaters: make(map[common.Address]precompileconfig.Predicater),
|
||||
AccepterPrecompiles: make(map[common.Address]precompileconfig.Accepter),
|
||||
}
|
||||
|
||||
// Add active precompiles based on upgrades
|
||||
for _, upgrade := range extra.PrecompileUpgrades {
|
||||
if upgrade.Timestamp() != nil && *upgrade.Timestamp() <= timestamp {
|
||||
// Get address from the registry based on the config
|
||||
address := getPrecompileAddress(upgrade.Config)
|
||||
if address == (common.Address{}) {
|
||||
continue // Skip if no address found
|
||||
}
|
||||
|
||||
if upgrade.IsDisabled() {
|
||||
delete(rules.Precompiles, address)
|
||||
delete(rules.Predicaters, address)
|
||||
delete(rules.AccepterPrecompiles, address)
|
||||
} else {
|
||||
rules.Precompiles[address] = upgrade.Config
|
||||
if predicater, ok := upgrade.Config.(precompileconfig.Predicater); ok {
|
||||
rules.Predicaters[address] = predicater
|
||||
}
|
||||
if accepter, ok := upgrade.Config.(precompileconfig.Accepter); ok {
|
||||
rules.AccepterPrecompiles[address] = accepter
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add genesis precompiles if at genesis
|
||||
if timestamp == 0 {
|
||||
for address, config := range extra.GenesisPrecompiles {
|
||||
if !config.IsDisabled() {
|
||||
rules.Precompiles[address] = config
|
||||
if predicater, ok := config.(precompileconfig.Predicater); ok {
|
||||
rules.Predicaters[address] = predicater
|
||||
}
|
||||
if accepter, ok := config.(precompileconfig.Accepter); ok {
|
||||
rules.AccepterPrecompiles[address] = accepter
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rules
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ type UpgradeConfig struct {
|
||||
|
||||
// LuxContext provides Lux specific context directly into the EVM.
|
||||
type LuxContext struct {
|
||||
SnowCtx *consensus.Context
|
||||
ConsensusCtx *consensus.Context
|
||||
}
|
||||
|
||||
type ChainConfig struct {
|
||||
|
||||
@@ -147,7 +147,7 @@ func TestChainConfigVerify(t *testing.T) {
|
||||
NetworkUpgrades: NetworkUpgrades{
|
||||
SubnetEVMTimestamp: nil,
|
||||
},
|
||||
LuxContext: LuxContext{SnowCtx: &consensus.Context{}},
|
||||
LuxContext: LuxContext{ConsensusCtx: &consensus.Context{}},
|
||||
},
|
||||
errRegex: "^invalid network upgrades: ",
|
||||
},
|
||||
@@ -160,7 +160,7 @@ func TestChainConfigVerify(t *testing.T) {
|
||||
EtnaTimestamp: pointer(uint64(3)),
|
||||
FortunaTimestamp: pointer(uint64(4)),
|
||||
},
|
||||
LuxContext: LuxContext{SnowCtx: &consensus.Context{
|
||||
LuxContext: LuxContext{ConsensusCtx: &consensus.Context{
|
||||
NetworkUpgrades: upgrade.Config{
|
||||
DurangoTime: time.Unix(2, 0),
|
||||
EtnaTime: time.Unix(3, 0),
|
||||
|
||||
@@ -24,7 +24,7 @@ func TestVerifyWithChainConfig(t *testing.T) {
|
||||
admins := []common.Address{{1}}
|
||||
copy := *TestChainConfig
|
||||
config := ©
|
||||
config.SnowCtx = utilstest.NewTestSnowContext(t)
|
||||
config.ConsensusCtx = utilstest.NewTestConsensusContext(t)
|
||||
config.GenesisPrecompiles = Precompiles{
|
||||
txallowlist.ConfigKey: txallowlist.NewConfig(utils.NewUint64(2), nil, nil, nil),
|
||||
}
|
||||
@@ -70,7 +70,7 @@ func TestVerifyWithChainConfigAtNilTimestamp(t *testing.T) {
|
||||
admins := []common.Address{{0}}
|
||||
copy := *TestChainConfig
|
||||
config := ©
|
||||
config.SnowCtx = utilstest.NewTestSnowContext(t)
|
||||
config.ConsensusCtx = utilstest.NewTestConsensusContext(t)
|
||||
config.PrecompileUpgrades = []PrecompileUpgrade{
|
||||
// this does NOT enable the precompile, so it should be upgradeable.
|
||||
{Config: txallowlist.NewConfig(nil, nil, nil, nil)},
|
||||
@@ -191,7 +191,7 @@ func TestVerifyPrecompileUpgrades(t *testing.T) {
|
||||
require := require.New(t)
|
||||
copy := *TestChainConfig
|
||||
config := ©
|
||||
config.SnowCtx = utilstest.NewTestSnowContext(t)
|
||||
config.ConsensusCtx = utilstest.NewTestConsensusContext(t)
|
||||
config.PrecompileUpgrades = tt.upgrades
|
||||
|
||||
err := config.Verify()
|
||||
@@ -236,7 +236,7 @@ func TestVerifyPrecompiles(t *testing.T) {
|
||||
require := require.New(t)
|
||||
copy := *TestChainConfig
|
||||
config := ©
|
||||
config.SnowCtx = utilstest.NewTestSnowContext(t)
|
||||
config.ConsensusCtx = utilstest.NewTestConsensusContext(t)
|
||||
config.GenesisPrecompiles = tt.precompiles
|
||||
|
||||
err := config.Verify()
|
||||
@@ -254,7 +254,7 @@ func TestVerifyRequiresSortedTimestamps(t *testing.T) {
|
||||
config := &ChainConfig{
|
||||
FeeConfig: DefaultFeeConfig,
|
||||
LuxContext: LuxContext{
|
||||
SnowCtx: utilstest.NewTestSnowContext(t),
|
||||
ConsensusCtx: utilstest.NewTestConsensusContext(t),
|
||||
},
|
||||
}
|
||||
config.PrecompileUpgrades = []PrecompileUpgrade{
|
||||
|
||||
@@ -62,7 +62,7 @@ func TestVerifyStateUpgrades(t *testing.T) {
|
||||
require := require.New(t)
|
||||
copy := *TestChainConfig
|
||||
config := ©
|
||||
config.SnowCtx = utilstest.NewTestSnowContext(t)
|
||||
config.ConsensusCtx = utilstest.NewTestConsensusContext(t)
|
||||
config.StateUpgrades = tt.upgrades
|
||||
|
||||
err := config.Verify()
|
||||
|
||||
+14
-14
@@ -28,18 +28,18 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
_ snowman.Block = (*Block)(nil)
|
||||
_ chain.Block = (*Block)(nil)
|
||||
_ block.WithVerifyContext = (*Block)(nil)
|
||||
)
|
||||
|
||||
// Block implements the snowman.Block interface
|
||||
// Block implements the chain.Block interface
|
||||
type Block struct {
|
||||
id ids.ID
|
||||
ethBlock *types.Block
|
||||
vm *VM
|
||||
}
|
||||
|
||||
// newBlock returns a new Block wrapping the ethBlock type and implementing the snowman.Block interface
|
||||
// newBlock returns a new Block wrapping the ethBlock type and implementing the chain.Block interface
|
||||
func (vm *VM) newBlock(ethBlock *types.Block) *Block {
|
||||
return &Block{
|
||||
id: ids.ID(ethBlock.Hash()),
|
||||
@@ -48,10 +48,10 @@ func (vm *VM) newBlock(ethBlock *types.Block) *Block {
|
||||
}
|
||||
}
|
||||
|
||||
// ID implements the snowman.Block interface
|
||||
// ID implements the chain.Block interface
|
||||
func (b *Block) ID() ids.ID { return b.id }
|
||||
|
||||
// Accept implements the snowman.Block interface
|
||||
// Accept implements the chain.Block interface
|
||||
func (b *Block) Accept(context.Context) error {
|
||||
vm := b.vm
|
||||
|
||||
@@ -100,7 +100,7 @@ func (b *Block) handlePrecompileAccept(rules extras.Rules) error {
|
||||
return fmt.Errorf("failed to fetch receipts for accepted block with non-empty root hash (%s) (Block: %s, Height: %d)", b.ethBlock.ReceiptHash(), b.ethBlock.Hash(), b.ethBlock.NumberU64())
|
||||
}
|
||||
acceptCtx := &precompileconfig.AcceptContext{
|
||||
SnowCtx: b.vm.ctx,
|
||||
ConsensusCtx: b.vm.ctx,
|
||||
Warp: b.vm.warpBackend,
|
||||
}
|
||||
for _, receipt := range receipts {
|
||||
@@ -118,7 +118,7 @@ func (b *Block) handlePrecompileAccept(rules extras.Rules) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reject implements the snowman.Block interface
|
||||
// Reject implements the chain.Block interface
|
||||
func (b *Block) Reject(context.Context) error {
|
||||
blkID := b.ID()
|
||||
log.Debug("rejecting block",
|
||||
@@ -129,17 +129,17 @@ func (b *Block) Reject(context.Context) error {
|
||||
return b.vm.blockChain.Reject(b.ethBlock)
|
||||
}
|
||||
|
||||
// Parent implements the snowman.Block interface
|
||||
// Parent implements the chain.Block interface
|
||||
func (b *Block) Parent() ids.ID {
|
||||
return ids.ID(b.ethBlock.ParentHash())
|
||||
}
|
||||
|
||||
// Height implements the snowman.Block interface
|
||||
// Height implements the chain.Block interface
|
||||
func (b *Block) Height() uint64 {
|
||||
return b.ethBlock.NumberU64()
|
||||
}
|
||||
|
||||
// Timestamp implements the snowman.Block interface
|
||||
// Timestamp implements the chain.Block interface
|
||||
func (b *Block) Timestamp() time.Time {
|
||||
return time.Unix(int64(b.ethBlock.Time()), 0)
|
||||
}
|
||||
@@ -155,10 +155,10 @@ func (b *Block) syntacticVerify() error {
|
||||
return b.vm.syntacticBlockValidator.SyntacticVerify(b, rules)
|
||||
}
|
||||
|
||||
// Verify implements the snowman.Block interface
|
||||
// Verify implements the chain.Block interface
|
||||
func (b *Block) Verify(context.Context) error {
|
||||
return b.verify(&precompileconfig.PredicateContext{
|
||||
SnowCtx: b.vm.ctx,
|
||||
ConsensusCtx: b.vm.ctx,
|
||||
ProposerVMBlockCtx: nil,
|
||||
}, true)
|
||||
}
|
||||
@@ -190,7 +190,7 @@ func (b *Block) ShouldVerifyWithContext(context.Context) (bool, error) {
|
||||
// VerifyWithContext implements the block.WithVerifyContext interface
|
||||
func (b *Block) VerifyWithContext(ctx context.Context, proposerVMBlockCtx *block.Context) error {
|
||||
return b.verify(&precompileconfig.PredicateContext{
|
||||
SnowCtx: b.vm.ctx,
|
||||
ConsensusCtx: b.vm.ctx,
|
||||
ProposerVMBlockCtx: proposerVMBlockCtx,
|
||||
}, true)
|
||||
}
|
||||
@@ -263,7 +263,7 @@ func (b *Block) verifyPredicates(predicateContext *precompileconfig.PredicateCon
|
||||
return nil
|
||||
}
|
||||
|
||||
// Bytes implements the snowman.Block interface
|
||||
// Bytes implements the chain.Block interface
|
||||
func (b *Block) Bytes() []byte {
|
||||
res, err := rlp.EncodeToBytes(b.ethBlock)
|
||||
if err != nil {
|
||||
|
||||
@@ -20,7 +20,7 @@ const (
|
||||
)
|
||||
|
||||
// var _ block.StateSummary = (*SyncSummary)(nil)
|
||||
// Note: StateSummary interface seems to be removed from node/consensus/engine/snowman/block
|
||||
// Note: StateSummary interface seems to be removed from node/consensus/engine/chain/block
|
||||
|
||||
// SyncSummary provides the information necessary to sync a node starting
|
||||
// at the given block.
|
||||
|
||||
@@ -36,9 +36,9 @@ import (
|
||||
func TestEthTxGossip(t *testing.T) {
|
||||
require := require.New(t)
|
||||
ctx := context.Background()
|
||||
snowCtx := utilstest.NewTestSnowContext(t)
|
||||
consensusCtx := utilstest.NewTestConsensusContext(t)
|
||||
validatorState := utilstest.NewTestValidatorState()
|
||||
snowCtx.ValidatorState = validatorState
|
||||
consensusCtx.ValidatorState = validatorState
|
||||
|
||||
responseSender := &enginetest.SenderStub{
|
||||
SentAppResponse: make(chan []byte, 1),
|
||||
@@ -47,7 +47,7 @@ func TestEthTxGossip(t *testing.T) {
|
||||
|
||||
require.NoError(vm.Initialize(
|
||||
ctx,
|
||||
snowCtx,
|
||||
consensusCtx,
|
||||
memdb.New(),
|
||||
[]byte(toGenesisJSON(forkToChainConfig[upgradetest.Latest])),
|
||||
nil,
|
||||
@@ -109,7 +109,7 @@ func TestEthTxGossip(t *testing.T) {
|
||||
}
|
||||
require.NoError(client.AppRequest(ctx, set.Of(vm.ctx.NodeID), requestBytes, onResponse))
|
||||
require.NoError(vm.AppRequest(ctx, requestingNodeID, 1, time.Time{}, <-peerSender.SentAppRequest))
|
||||
require.NoError(network.AppResponse(ctx, snowCtx.NodeID, 1, <-responseSender.SentAppResponse))
|
||||
require.NoError(network.AppResponse(ctx, consensusCtx.NodeID, 1, <-responseSender.SentAppResponse))
|
||||
wg.Wait()
|
||||
|
||||
// Issue a tx to the VM
|
||||
@@ -143,7 +143,7 @@ func TestEthTxGossip(t *testing.T) {
|
||||
}
|
||||
require.NoError(client.AppRequest(ctx, set.Of(vm.ctx.NodeID), requestBytes, onResponse))
|
||||
require.NoError(vm.AppRequest(ctx, requestingNodeID, 3, time.Time{}, <-peerSender.SentAppRequest))
|
||||
require.NoError(network.AppResponse(ctx, snowCtx.NodeID, 3, <-responseSender.SentAppResponse))
|
||||
require.NoError(network.AppResponse(ctx, consensusCtx.NodeID, 3, <-responseSender.SentAppResponse))
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ func TestEthTxGossip(t *testing.T) {
|
||||
func TestEthTxPushGossipOutbound(t *testing.T) {
|
||||
require := require.New(t)
|
||||
ctx := context.Background()
|
||||
snowCtx := utilstest.NewTestSnowContext(t)
|
||||
consensusCtx := utilstest.NewTestConsensusContext(t)
|
||||
sender := &enginetest.SenderStub{
|
||||
SentAppGossip: make(chan []byte, 1),
|
||||
}
|
||||
@@ -162,7 +162,7 @@ func TestEthTxPushGossipOutbound(t *testing.T) {
|
||||
|
||||
require.NoError(vm.Initialize(
|
||||
ctx,
|
||||
snowCtx,
|
||||
consensusCtx,
|
||||
memdb.New(),
|
||||
[]byte(toGenesisJSON(forkToChainConfig[upgradetest.Latest])),
|
||||
nil,
|
||||
@@ -204,7 +204,7 @@ func TestEthTxPushGossipOutbound(t *testing.T) {
|
||||
func TestEthTxPushGossipInbound(t *testing.T) {
|
||||
require := require.New(t)
|
||||
ctx := context.Background()
|
||||
snowCtx := utilstest.NewTestSnowContext(t)
|
||||
consensusCtx := utilstest.NewTestConsensusContext(t)
|
||||
|
||||
sender := &enginetest.Sender{}
|
||||
vm := &VM{
|
||||
@@ -213,7 +213,7 @@ func TestEthTxPushGossipInbound(t *testing.T) {
|
||||
|
||||
require.NoError(vm.Initialize(
|
||||
ctx,
|
||||
snowCtx,
|
||||
consensusCtx,
|
||||
memdb.New(),
|
||||
[]byte(toGenesisJSON(forkToChainConfig[upgradetest.Latest])),
|
||||
nil,
|
||||
|
||||
@@ -18,7 +18,7 @@ The package defines how to serialize the data according to the codec. It can rea
|
||||
|
||||
## Uptime Package
|
||||
|
||||
The uptime package manages the uptime tracking of the L1 validators. It wraps [Luxd's uptime tracking manager](https://pkg.go.dev/github.com/luxfi/luxd/snow/uptime) under the hood and additionally introduces pausable uptime manager interface. The pausable uptime manager interface allows the manager to pause the uptime tracking for a specific validator when it becomes `inactive` and resume it when it becomes `active` again.
|
||||
The uptime package manages the uptime tracking of the L1 validators. It wraps [Luxd's uptime tracking manager](https://pkg.go.dev/github.com/luxfi/luxd/consensus/uptime) under the hood and additionally introduces pausable uptime manager interface. The pausable uptime manager interface allows the manager to pause the uptime tracking for a specific validator when it becomes `inactive` and resume it when it becomes `active` again.
|
||||
|
||||
The uptime package must be run on at least one L1 node, referred to in this document as the "tracker node".
|
||||
|
||||
|
||||
+12
-12
@@ -130,7 +130,7 @@ const (
|
||||
var (
|
||||
// Set last accepted key to be longer than the keys used to store accepted block IDs.
|
||||
lastAcceptedKey = []byte("last_accepted_key")
|
||||
acceptedPrefix = []byte("snowman_accepted")
|
||||
acceptedPrefix = []byte("chain_accepted")
|
||||
metadataPrefix = []byte("metadata")
|
||||
warpPrefix = []byte("warp")
|
||||
ethDBPrefix = []byte("ethdb")
|
||||
@@ -169,7 +169,7 @@ var legacyApiNames = map[string]string{
|
||||
"private-debug": "debug",
|
||||
}
|
||||
|
||||
// VM implements the snowman.ChainVM interface
|
||||
// VM implements the chain.ChainVM interface
|
||||
type VM struct {
|
||||
ctx *consensus.Context
|
||||
// contextLock is used to coordinate global VM operations.
|
||||
@@ -263,7 +263,7 @@ type VM struct {
|
||||
rpcHandlers []interface{ Stop() }
|
||||
}
|
||||
|
||||
// Initialize implements the snowman.ChainVM interface
|
||||
// Initialize implements the chain.ChainVM interface
|
||||
func (vm *VM) Initialize(
|
||||
_ context.Context,
|
||||
chainCtx *consensus.Context,
|
||||
@@ -528,7 +528,7 @@ func parseGenesis(ctx *consensus.Context, genesisBytes []byte, upgradeBytes []by
|
||||
// Populate the Lux config extras.
|
||||
configExtra := params.GetExtra(g.Config)
|
||||
configExtra.LuxContext = extras.LuxContext{
|
||||
SnowCtx: ctx,
|
||||
ConsensusCtx: ctx,
|
||||
}
|
||||
|
||||
if configExtra.FeeConfig == commontype.EmptyFeeConfig {
|
||||
@@ -919,7 +919,7 @@ func (vm *VM) WaitForEvent(ctx context.Context) (commonEng.Message, error) {
|
||||
return builder.waitForEvent(ctx)
|
||||
}
|
||||
|
||||
// Shutdown implements the snowman.ChainVM interface
|
||||
// Shutdown implements the chain.ChainVM interface
|
||||
func (vm *VM) Shutdown(context.Context) error {
|
||||
vm.vmLock.Lock()
|
||||
defer vm.vmLock.Unlock()
|
||||
@@ -958,18 +958,18 @@ func (vm *VM) Shutdown(context.Context) error {
|
||||
}
|
||||
|
||||
// buildBlock builds a block to be wrapped by ChainState
|
||||
func (vm *VM) buildBlock(ctx context.Context) (snowman.Block, error) {
|
||||
func (vm *VM) buildBlock(ctx context.Context) (chain.Block, error) {
|
||||
return vm.buildBlockWithContext(ctx, nil)
|
||||
}
|
||||
|
||||
func (vm *VM) buildBlockWithContext(ctx context.Context, proposerVMBlockCtx *block.Context) (snowman.Block, error) {
|
||||
func (vm *VM) buildBlockWithContext(ctx context.Context, proposerVMBlockCtx *block.Context) (chain.Block, error) {
|
||||
if proposerVMBlockCtx != nil {
|
||||
log.Debug("Building block with context", "pChainBlockHeight", proposerVMBlockCtx.PChainHeight)
|
||||
} else {
|
||||
log.Debug("Building block without context")
|
||||
}
|
||||
predicateCtx := &precompileconfig.PredicateContext{
|
||||
SnowCtx: vm.ctx,
|
||||
ConsensusCtx: vm.ctx,
|
||||
ProposerVMBlockCtx: proposerVMBlockCtx,
|
||||
}
|
||||
|
||||
@@ -1007,7 +1007,7 @@ func (vm *VM) buildBlockWithContext(ctx context.Context, proposerVMBlockCtx *blo
|
||||
}
|
||||
|
||||
// parseBlock parses [b] into a block to be wrapped by ChainState.
|
||||
func (vm *VM) parseBlock(_ context.Context, b []byte) (snowman.Block, error) {
|
||||
func (vm *VM) parseBlock(_ context.Context, b []byte) (chain.Block, error) {
|
||||
ethBlock := new(types.Block)
|
||||
if err := rlp.DecodeBytes(b, ethBlock); err != nil {
|
||||
return nil, err
|
||||
@@ -1034,7 +1034,7 @@ func (vm *VM) ParseEthBlock(b []byte) (*types.Block, error) {
|
||||
|
||||
// getBlock attempts to retrieve block [id] from the VM to be wrapped
|
||||
// by ChainState.
|
||||
func (vm *VM) getBlock(_ context.Context, id ids.ID) (snowman.Block, error) {
|
||||
func (vm *VM) getBlock(_ context.Context, id ids.ID) (chain.Block, error) {
|
||||
ethBlock := vm.blockChain.GetBlockByHash(common.Hash(id))
|
||||
// If [ethBlock] is nil, return [database.ErrNotFound] here
|
||||
// so that the miss is considered cacheable.
|
||||
@@ -1047,7 +1047,7 @@ func (vm *VM) getBlock(_ context.Context, id ids.ID) (snowman.Block, error) {
|
||||
|
||||
// GetAcceptedBlock attempts to retrieve block [blkID] from the VM. This method
|
||||
// only returns accepted blocks.
|
||||
func (vm *VM) GetAcceptedBlock(ctx context.Context, blkID ids.ID) (snowman.Block, error) {
|
||||
func (vm *VM) GetAcceptedBlock(ctx context.Context, blkID ids.ID) (chain.Block, error) {
|
||||
blk, err := vm.GetBlock(ctx, blkID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -1212,7 +1212,7 @@ func (vm *VM) chainConfigExtra() *extras.ChainConfig {
|
||||
|
||||
func (vm *VM) rules(number *big.Int, time uint64) extras.Rules {
|
||||
ethrules := vm.chainConfig.Rules(number, params.IsMergeTODO, time)
|
||||
return *params.GetRulesExtra(ethrules)
|
||||
return *params.GetExtrasRules(ethrules, vm.chainConfig, time)
|
||||
}
|
||||
|
||||
// currentRules returns the chain rules for the current block.
|
||||
|
||||
@@ -143,7 +143,7 @@ type testVM struct {
|
||||
}
|
||||
|
||||
func newVM(t *testing.T, config testVMConfig) *testVM {
|
||||
ctx := utilstest.NewTestSnowContext(t)
|
||||
ctx := utilstest.NewTestConsensusContext(t)
|
||||
fork := upgradetest.Latest
|
||||
if config.fork != nil {
|
||||
fork = *config.fork
|
||||
@@ -218,7 +218,7 @@ func setupGenesis(
|
||||
[]byte,
|
||||
*atomic.Memory,
|
||||
) {
|
||||
ctx := utilstest.NewTestSnowContext(t)
|
||||
ctx := utilstest.NewTestConsensusContext(t)
|
||||
|
||||
genesisJSON := toGenesisJSON(forkToChainConfig[fork])
|
||||
ctx.NetworkUpgrades = upgradetest.GetConfig(fork)
|
||||
@@ -352,7 +352,7 @@ func testVMUpgrades(t *testing.T, scheme string) {
|
||||
}
|
||||
}
|
||||
|
||||
func issueAndAccept(t *testing.T, vm *VM) snowman.Block {
|
||||
func issueAndAccept(t *testing.T, vm *VM) chain.Block {
|
||||
t.Helper()
|
||||
|
||||
msg, err := vm.WaitForEvent(context.Background())
|
||||
@@ -477,7 +477,7 @@ func testBuildEthTxBlock(t *testing.T, scheme string) {
|
||||
}
|
||||
|
||||
restartedVM := &VM{}
|
||||
newCTX := utilstest.NewTestSnowContext(t)
|
||||
newCTX := utilstest.NewTestConsensusContext(t)
|
||||
newCTX.NetworkUpgrades = upgradetest.GetConfig(fork)
|
||||
newCTX.ChainDataDir = tvm.vm.ctx.ChainDataDir
|
||||
if err := restartedVM.Initialize(
|
||||
@@ -3311,7 +3311,7 @@ func TestParentBeaconRootBlock(t *testing.T) {
|
||||
|
||||
func TestStandaloneDB(t *testing.T) {
|
||||
vm := &VM{}
|
||||
ctx := utilstest.NewTestSnowContext(t)
|
||||
ctx := utilstest.NewTestConsensusContext(t)
|
||||
baseDB := memdb.New()
|
||||
atomicMemory := atomic.NewMemory(prefixdb.New([]byte{0}, baseDB))
|
||||
ctx.SharedMemory = atomicMemory.NewSharedMemory(ctx.ChainID)
|
||||
|
||||
@@ -96,7 +96,7 @@ func TestValidatorState(t *testing.T) {
|
||||
vm = &VM{}
|
||||
err = vm.Initialize(
|
||||
context.Background(),
|
||||
utilstest.NewTestSnowContext(t), // this context does not have validators state, making VM to source it from the database
|
||||
utilstest.NewTestConsensusContext(t), // this context does not have validators state, making VM to source it from the database
|
||||
dbManager,
|
||||
genesisBytes,
|
||||
[]byte(""),
|
||||
|
||||
@@ -51,7 +51,7 @@ type StateDB interface {
|
||||
type AccessibleState interface {
|
||||
GetStateDB() StateDB
|
||||
GetBlockContext() BlockContext
|
||||
GetSnowContext() *consensus.Context
|
||||
GetConsensusContext() *consensus.Context
|
||||
GetChainConfig() precompileconfig.ChainConfig
|
||||
}
|
||||
|
||||
|
||||
@@ -139,18 +139,18 @@ func (mr *MockAccessibleStateMockRecorder) GetChainConfig() *gomock.Call {
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetChainConfig", reflect.TypeOf((*MockAccessibleState)(nil).GetChainConfig))
|
||||
}
|
||||
|
||||
// GetSnowContext mocks base method.
|
||||
func (m *MockAccessibleState) GetSnowContext() *consensus.Context {
|
||||
// GetConsensusContext mocks base method.
|
||||
func (m *MockAccessibleState) GetConsensusContext() *consensus.Context {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetSnowContext")
|
||||
ret := m.ctrl.Call(m, "GetConsensusContext")
|
||||
ret0, _ := ret[0].(*consensus.Context)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// GetSnowContext indicates an expected call of GetSnowContext.
|
||||
func (mr *MockAccessibleStateMockRecorder) GetSnowContext() *gomock.Call {
|
||||
// GetConsensusContext indicates an expected call of GetConsensusContext.
|
||||
func (mr *MockAccessibleStateMockRecorder) GetConsensusContext() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSnowContext", reflect.TypeOf((*MockAccessibleState)(nil).GetSnowContext))
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetConsensusContext", reflect.TypeOf((*MockAccessibleState)(nil).GetConsensusContext))
|
||||
}
|
||||
|
||||
// GetStateDB mocks base method.
|
||||
|
||||
@@ -201,9 +201,9 @@ func (c *Config) VerifyPredicate(predicateContext *precompileconfig.PredicateCon
|
||||
|
||||
log.Debug("verifying warp message", "warpMsg", warpMsg, "quorumNum", quorumNumerator, "quorumDenom", WarpQuorumDenominator)
|
||||
|
||||
// Wrap validators.State on the chain snow context to special case the Primary Network
|
||||
// Wrap validators.State on the chain consensus context to special case the Primary Network
|
||||
// Type assert ValidatorState to the expected validators.State interface
|
||||
_, ok := predicateContext.SnowCtx.ValidatorState.(validators.State)
|
||||
_, ok := predicateContext.ConsensusCtx.ValidatorState.(validators.State)
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid validator state type")
|
||||
}
|
||||
@@ -217,7 +217,7 @@ func (c *Config) VerifyPredicate(predicateContext *precompileconfig.PredicateCon
|
||||
// err := warpMsg.Signature.Verify(
|
||||
// context.Background(),
|
||||
// &warpMsg.UnsignedMessage,
|
||||
// predicateContext.SnowCtx.NetworkID,
|
||||
// predicateContext.ConsensusCtx.NetworkID,
|
||||
// validatorState, // Use the validator state instead of validatorSet
|
||||
// quorumNumerator,
|
||||
// WarpQuorumDenominator,
|
||||
|
||||
@@ -90,12 +90,12 @@ func PackGetBlockchainIDOutput(blockchainID common.Hash) ([]byte, error) {
|
||||
return WarpABI.PackOutput("getBlockchainID", blockchainID)
|
||||
}
|
||||
|
||||
// getBlockchainID returns the snow Chain Context ChainID of this blockchain.
|
||||
// getBlockchainID returns the consensus Chain Context ChainID of this blockchain.
|
||||
func getBlockchainID(accessibleState contract.AccessibleState, caller common.Address, addr common.Address, input []byte, suppliedGas uint64, readOnly bool) (ret []byte, remainingGas uint64, err error) {
|
||||
if remainingGas, err = contract.DeductGas(suppliedGas, GetBlockchainIDGasCost); err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
packedOutput, err := PackGetBlockchainIDOutput(common.Hash(accessibleState.GetSnowContext().ChainID))
|
||||
packedOutput, err := PackGetBlockchainIDOutput(common.Hash(accessibleState.GetConsensusContext().ChainID))
|
||||
if err != nil {
|
||||
return nil, remainingGas, err
|
||||
}
|
||||
@@ -250,7 +250,7 @@ func sendWarpMessage(accessibleState contract.AccessibleState, caller common.Add
|
||||
}
|
||||
|
||||
var (
|
||||
sourceChainID = accessibleState.GetSnowContext().ChainID
|
||||
sourceChainID = accessibleState.GetConsensusContext().ChainID
|
||||
sourceAddress = caller
|
||||
)
|
||||
|
||||
@@ -262,7 +262,7 @@ func sendWarpMessage(accessibleState contract.AccessibleState, caller common.Add
|
||||
return nil, remainingGas, err
|
||||
}
|
||||
unsignedWarpMessage, err := warp.NewUnsignedMessage(
|
||||
accessibleState.GetSnowContext().NetworkID,
|
||||
accessibleState.GetConsensusContext().NetworkID,
|
||||
sourceChainID,
|
||||
addressedPayload.Bytes(),
|
||||
)
|
||||
|
||||
@@ -26,8 +26,8 @@ import (
|
||||
func TestGetBlockchainID(t *testing.T) {
|
||||
callerAddr := common.HexToAddress("0x0123")
|
||||
|
||||
defaultSnowCtx := utilstest.NewTestSnowContext(t)
|
||||
blockchainID := defaultSnowCtx.ChainID
|
||||
defaultConsensusCtx := utilstest.NewTestConsensusContext(t)
|
||||
blockchainID := defaultConsensusCtx.ChainID
|
||||
|
||||
tests := map[string]precompiletest.PrecompileTest{
|
||||
"getBlockchainID success": {
|
||||
@@ -84,8 +84,8 @@ func TestGetBlockchainID(t *testing.T) {
|
||||
func TestSendWarpMessage(t *testing.T) {
|
||||
callerAddr := common.HexToAddress("0x0123")
|
||||
|
||||
defaultSnowCtx := utilstest.NewTestSnowContext(t)
|
||||
blockchainID := defaultSnowCtx.ChainID
|
||||
defaultConsensusCtx := utilstest.NewTestConsensusContext(t)
|
||||
blockchainID := defaultConsensusCtx.ChainID
|
||||
sendWarpMessagePayload := agoUtils.RandomBytes(100)
|
||||
|
||||
sendWarpMessageInput, err := PackSendWarpMessage(sendWarpMessagePayload)
|
||||
@@ -96,7 +96,7 @@ func TestSendWarpMessage(t *testing.T) {
|
||||
)
|
||||
require.NoError(t, err)
|
||||
unsignedWarpMessage, err := luxWarp.NewUnsignedMessage(
|
||||
defaultSnowCtx.NetworkID,
|
||||
defaultConsensusCtx.NetworkID,
|
||||
blockchainID,
|
||||
sendWarpMessageAddressedPayload.Bytes(),
|
||||
)
|
||||
|
||||
@@ -169,8 +169,8 @@ type validatorRange struct {
|
||||
publicKey bool
|
||||
}
|
||||
|
||||
// createSnowCtx creates a consensus.Context instance with a validator state specified by the given validatorRanges
|
||||
func createSnowCtx(tb testing.TB, validatorRanges []validatorRange) *consensus.Context {
|
||||
// createConsensusCtx creates a consensus.Context instance with a validator state specified by the given validatorRanges
|
||||
func createConsensusCtx(tb testing.TB, validatorRanges []validatorRange) *consensus.Context {
|
||||
getValidatorsOutput := make(map[ids.NodeID]*validators.GetValidatorOutput)
|
||||
|
||||
for _, validatorRange := range validatorRanges {
|
||||
@@ -186,7 +186,7 @@ func createSnowCtx(tb testing.TB, validatorRanges []validatorRange) *consensus.C
|
||||
}
|
||||
}
|
||||
|
||||
snowCtx := utilstest.NewTestSnowContext(tb)
|
||||
consensusCtx := utilstest.NewTestConsensusContext(tb)
|
||||
state := &validatorstest.State{
|
||||
GetSubnetIDF: func(ctx context.Context, chainID ids.ID) (ids.ID, error) {
|
||||
return sourceSubnetID, nil
|
||||
@@ -195,15 +195,15 @@ func createSnowCtx(tb testing.TB, validatorRanges []validatorRange) *consensus.C
|
||||
return getValidatorsOutput, nil
|
||||
},
|
||||
}
|
||||
snowCtx.ValidatorState = state
|
||||
return snowCtx
|
||||
consensusCtx.ValidatorState = state
|
||||
return consensusCtx
|
||||
}
|
||||
|
||||
func createValidPredicateTest(snowCtx *consensus.Context, numKeys uint64, predicateBytes []byte) precompiletest.PredicateTest {
|
||||
func createValidPredicateTest(consensusCtx *consensus.Context, numKeys uint64, predicateBytes []byte) precompiletest.PredicateTest {
|
||||
return precompiletest.PredicateTest{
|
||||
Config: NewDefaultConfig(utils.NewUint64(0)),
|
||||
PredicateContext: &precompileconfig.PredicateContext{
|
||||
SnowCtx: snowCtx,
|
||||
ConsensusCtx: consensusCtx,
|
||||
ProposerVMBlockCtx: &block.Context{
|
||||
PChainHeight: 1,
|
||||
},
|
||||
@@ -259,17 +259,17 @@ func testWarpMessageFromPrimaryNetwork(t *testing.T, requirePrimaryNetworkSigner
|
||||
|
||||
predicateBytes := predicate.PackPredicate(warpMsg.Bytes())
|
||||
|
||||
snowCtx := utilstest.NewTestSnowContext(t)
|
||||
snowCtx.SubnetID = ids.GenerateTestID()
|
||||
snowCtx.ChainID = ids.GenerateTestID()
|
||||
snowCtx.CChainID = cChainID
|
||||
snowCtx.ValidatorState = &validatorstest.State{
|
||||
consensusCtx := utilstest.NewTestConsensusContext(t)
|
||||
consensusCtx.SubnetID = ids.GenerateTestID()
|
||||
consensusCtx.ChainID = ids.GenerateTestID()
|
||||
consensusCtx.CChainID = cChainID
|
||||
consensusCtx.ValidatorState = &validatorstest.State{
|
||||
GetSubnetIDF: func(ctx context.Context, chainID ids.ID) (ids.ID, error) {
|
||||
require.Equal(chainID, cChainID)
|
||||
return constants.PrimaryNetworkID, nil // Return Primary Network SubnetID
|
||||
},
|
||||
GetValidatorSetF: func(ctx context.Context, height uint64, subnetID ids.ID) (map[ids.NodeID]*validators.GetValidatorOutput, error) {
|
||||
expectedSubnetID := snowCtx.SubnetID
|
||||
expectedSubnetID := consensusCtx.SubnetID
|
||||
if requirePrimaryNetworkSigners {
|
||||
expectedSubnetID = constants.PrimaryNetworkID
|
||||
}
|
||||
@@ -281,7 +281,7 @@ func testWarpMessageFromPrimaryNetwork(t *testing.T, requirePrimaryNetworkSigner
|
||||
test := precompiletest.PredicateTest{
|
||||
Config: NewConfig(utils.NewUint64(0), 0, requirePrimaryNetworkSigners),
|
||||
PredicateContext: &precompileconfig.PredicateContext{
|
||||
SnowCtx: snowCtx,
|
||||
ConsensusCtx: consensusCtx,
|
||||
ProposerVMBlockCtx: &block.Context{
|
||||
PChainHeight: 1,
|
||||
},
|
||||
@@ -297,7 +297,7 @@ func testWarpMessageFromPrimaryNetwork(t *testing.T, requirePrimaryNetworkSigner
|
||||
|
||||
func TestInvalidPredicatePacking(t *testing.T) {
|
||||
numKeys := 1
|
||||
snowCtx := createSnowCtx(t, []validatorRange{
|
||||
consensusCtx := createConsensusCtx(t, []validatorRange{
|
||||
{
|
||||
start: 0,
|
||||
end: numKeys,
|
||||
@@ -311,7 +311,7 @@ func TestInvalidPredicatePacking(t *testing.T) {
|
||||
test := precompiletest.PredicateTest{
|
||||
Config: NewDefaultConfig(utils.NewUint64(0)),
|
||||
PredicateContext: &precompileconfig.PredicateContext{
|
||||
SnowCtx: snowCtx,
|
||||
ConsensusCtx: consensusCtx,
|
||||
ProposerVMBlockCtx: &block.Context{
|
||||
PChainHeight: 1,
|
||||
},
|
||||
@@ -326,7 +326,7 @@ func TestInvalidPredicatePacking(t *testing.T) {
|
||||
|
||||
func TestInvalidWarpMessage(t *testing.T) {
|
||||
numKeys := 1
|
||||
snowCtx := createSnowCtx(t, []validatorRange{
|
||||
consensusCtx := createConsensusCtx(t, []validatorRange{
|
||||
{
|
||||
start: 0,
|
||||
end: numKeys,
|
||||
@@ -342,7 +342,7 @@ func TestInvalidWarpMessage(t *testing.T) {
|
||||
test := precompiletest.PredicateTest{
|
||||
Config: NewDefaultConfig(utils.NewUint64(0)),
|
||||
PredicateContext: &precompileconfig.PredicateContext{
|
||||
SnowCtx: snowCtx,
|
||||
ConsensusCtx: consensusCtx,
|
||||
ProposerVMBlockCtx: &block.Context{
|
||||
PChainHeight: 1,
|
||||
},
|
||||
@@ -357,7 +357,7 @@ func TestInvalidWarpMessage(t *testing.T) {
|
||||
|
||||
func TestInvalidAddressedPayload(t *testing.T) {
|
||||
numKeys := 1
|
||||
snowCtx := createSnowCtx(t, []validatorRange{
|
||||
consensusCtx := createConsensusCtx(t, []validatorRange{
|
||||
{
|
||||
start: 0,
|
||||
end: numKeys,
|
||||
@@ -386,7 +386,7 @@ func TestInvalidAddressedPayload(t *testing.T) {
|
||||
test := precompiletest.PredicateTest{
|
||||
Config: NewDefaultConfig(utils.NewUint64(0)),
|
||||
PredicateContext: &precompileconfig.PredicateContext{
|
||||
SnowCtx: snowCtx,
|
||||
ConsensusCtx: consensusCtx,
|
||||
ProposerVMBlockCtx: &block.Context{
|
||||
PChainHeight: 1,
|
||||
},
|
||||
@@ -419,7 +419,7 @@ func TestInvalidBitSet(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
numKeys := 1
|
||||
snowCtx := createSnowCtx(t, []validatorRange{
|
||||
consensusCtx := createConsensusCtx(t, []validatorRange{
|
||||
{
|
||||
start: 0,
|
||||
end: numKeys,
|
||||
@@ -431,7 +431,7 @@ func TestInvalidBitSet(t *testing.T) {
|
||||
test := precompiletest.PredicateTest{
|
||||
Config: NewDefaultConfig(utils.NewUint64(0)),
|
||||
PredicateContext: &precompileconfig.PredicateContext{
|
||||
SnowCtx: snowCtx,
|
||||
ConsensusCtx: consensusCtx,
|
||||
ProposerVMBlockCtx: &block.Context{
|
||||
PChainHeight: 1,
|
||||
},
|
||||
@@ -445,7 +445,7 @@ func TestInvalidBitSet(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWarpSignatureWeightsDefaultQuorumNumerator(t *testing.T) {
|
||||
snowCtx := createSnowCtx(t, []validatorRange{
|
||||
consensusCtx := createConsensusCtx(t, []validatorRange{
|
||||
{
|
||||
start: 0,
|
||||
end: 100,
|
||||
@@ -476,7 +476,7 @@ func TestWarpSignatureWeightsDefaultQuorumNumerator(t *testing.T) {
|
||||
tests[fmt.Sprintf("default quorum %d signature(s)", numSigners)] = precompiletest.PredicateTest{
|
||||
Config: NewDefaultConfig(utils.NewUint64(0)),
|
||||
PredicateContext: &precompileconfig.PredicateContext{
|
||||
SnowCtx: snowCtx,
|
||||
ConsensusCtx: consensusCtx,
|
||||
ProposerVMBlockCtx: &block.Context{
|
||||
PChainHeight: 1,
|
||||
},
|
||||
@@ -492,7 +492,7 @@ func TestWarpSignatureWeightsDefaultQuorumNumerator(t *testing.T) {
|
||||
|
||||
// multiple messages all correct, multiple messages all incorrect, mixed bag
|
||||
func TestWarpMultiplePredicates(t *testing.T) {
|
||||
snowCtx := createSnowCtx(t, []validatorRange{
|
||||
consensusCtx := createConsensusCtx(t, []validatorRange{
|
||||
{
|
||||
start: 0,
|
||||
end: 100,
|
||||
@@ -534,7 +534,7 @@ func TestWarpMultiplePredicates(t *testing.T) {
|
||||
tests[fmt.Sprintf("multiple predicates %v", validMessageIndices)] = precompiletest.PredicateTest{
|
||||
Config: NewDefaultConfig(utils.NewUint64(0)),
|
||||
PredicateContext: &precompileconfig.PredicateContext{
|
||||
SnowCtx: snowCtx,
|
||||
ConsensusCtx: consensusCtx,
|
||||
ProposerVMBlockCtx: &block.Context{
|
||||
PChainHeight: 1,
|
||||
},
|
||||
@@ -550,7 +550,7 @@ func TestWarpMultiplePredicates(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWarpSignatureWeightsNonDefaultQuorumNumerator(t *testing.T) {
|
||||
snowCtx := createSnowCtx(t, []validatorRange{
|
||||
consensusCtx := createConsensusCtx(t, []validatorRange{
|
||||
{
|
||||
start: 0,
|
||||
end: 100,
|
||||
@@ -578,7 +578,7 @@ func TestWarpSignatureWeightsNonDefaultQuorumNumerator(t *testing.T) {
|
||||
tests[name] = precompiletest.PredicateTest{
|
||||
Config: NewConfig(utils.NewUint64(0), uint64(nonDefaultQuorumNumerator), false),
|
||||
PredicateContext: &precompileconfig.PredicateContext{
|
||||
SnowCtx: snowCtx,
|
||||
ConsensusCtx: consensusCtx,
|
||||
ProposerVMBlockCtx: &block.Context{
|
||||
PChainHeight: 1,
|
||||
},
|
||||
@@ -599,7 +599,7 @@ func makeWarpPredicateTests(tb testing.TB) map[string]precompiletest.PredicateTe
|
||||
testName := fmt.Sprintf("%d signers/%d validators", totalNodes, totalNodes)
|
||||
|
||||
predicateBytes := createPredicate(totalNodes)
|
||||
snowCtx := createSnowCtx(tb, []validatorRange{
|
||||
consensusCtx := createConsensusCtx(tb, []validatorRange{
|
||||
{
|
||||
start: 0,
|
||||
end: totalNodes,
|
||||
@@ -607,7 +607,7 @@ func makeWarpPredicateTests(tb testing.TB) map[string]precompiletest.PredicateTe
|
||||
publicKey: true,
|
||||
},
|
||||
})
|
||||
predicateTests[testName] = createValidPredicateTest(snowCtx, uint64(totalNodes), predicateBytes)
|
||||
predicateTests[testName] = createValidPredicateTest(consensusCtx, uint64(totalNodes), predicateBytes)
|
||||
}
|
||||
|
||||
numSigners := 10
|
||||
@@ -615,7 +615,7 @@ func makeWarpPredicateTests(tb testing.TB) map[string]precompiletest.PredicateTe
|
||||
testName := fmt.Sprintf("%d signers (heavily weighted)/%d validators", numSigners, totalNodes)
|
||||
|
||||
predicateBytes := createPredicate(numSigners)
|
||||
snowCtx := createSnowCtx(tb, []validatorRange{
|
||||
consensusCtx := createConsensusCtx(tb, []validatorRange{
|
||||
{
|
||||
start: 0,
|
||||
end: numSigners,
|
||||
@@ -629,14 +629,14 @@ func makeWarpPredicateTests(tb testing.TB) map[string]precompiletest.PredicateTe
|
||||
publicKey: true,
|
||||
},
|
||||
})
|
||||
predicateTests[testName] = createValidPredicateTest(snowCtx, uint64(numSigners), predicateBytes)
|
||||
predicateTests[testName] = createValidPredicateTest(consensusCtx, uint64(numSigners), predicateBytes)
|
||||
}
|
||||
|
||||
for _, totalNodes := range []int{100, 1_000, 10_000} {
|
||||
testName := fmt.Sprintf("%d signers (heavily weighted)/%d validators (non-signers without registered PublicKey)", numSigners, totalNodes)
|
||||
|
||||
predicateBytes := createPredicate(numSigners)
|
||||
snowCtx := createSnowCtx(tb, []validatorRange{
|
||||
consensusCtx := createConsensusCtx(tb, []validatorRange{
|
||||
{
|
||||
start: 0,
|
||||
end: numSigners,
|
||||
@@ -650,7 +650,7 @@ func makeWarpPredicateTests(tb testing.TB) map[string]precompiletest.PredicateTe
|
||||
publicKey: false,
|
||||
},
|
||||
})
|
||||
predicateTests[testName] = createValidPredicateTest(snowCtx, uint64(numSigners), predicateBytes)
|
||||
predicateTests[testName] = createValidPredicateTest(consensusCtx, uint64(numSigners), predicateBytes)
|
||||
}
|
||||
|
||||
for _, totalNodes := range []int{100, 1_000, 10_000} {
|
||||
@@ -666,7 +666,7 @@ func makeWarpPredicateTests(tb testing.TB) map[string]precompiletest.PredicateTe
|
||||
}
|
||||
}
|
||||
|
||||
snowCtx := utilstest.NewTestSnowContext(tb)
|
||||
consensusCtx := utilstest.NewTestConsensusContext(tb)
|
||||
|
||||
state := &validatorstest.State{
|
||||
GetSubnetIDF: func(ctx context.Context, chainID ids.ID) (ids.ID, error) {
|
||||
@@ -676,9 +676,9 @@ func makeWarpPredicateTests(tb testing.TB) map[string]precompiletest.PredicateTe
|
||||
return getValidatorsOutput, nil
|
||||
},
|
||||
}
|
||||
snowCtx.ValidatorState = state
|
||||
consensusCtx.ValidatorState = state
|
||||
|
||||
predicateTests[testName] = createValidPredicateTest(snowCtx, uint64(numSigners), predicateBytes)
|
||||
predicateTests[testName] = createValidPredicateTest(consensusCtx, uint64(numSigners), predicateBytes)
|
||||
}
|
||||
return predicateTests
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ type Config interface {
|
||||
// PredicateContext is the context passed in to the Predicater interface to verify
|
||||
// a precompile predicate within a specific ProposerVM wrapper.
|
||||
type PredicateContext struct {
|
||||
SnowCtx *consensus.Context
|
||||
ConsensusCtx *consensus.Context
|
||||
// ProposerVMBlockCtx defines the ProposerVM context the predicate is verified within
|
||||
ProposerVMBlockCtx *block.Context
|
||||
}
|
||||
@@ -58,7 +58,7 @@ type WarpMessageWriter interface {
|
||||
|
||||
// AcceptContext defines the context passed in to a precompileconfig's Accepter
|
||||
type AcceptContext struct {
|
||||
SnowCtx *consensus.Context
|
||||
ConsensusCtx *consensus.Context
|
||||
Warp WarpMessageWriter
|
||||
}
|
||||
|
||||
|
||||
@@ -116,12 +116,12 @@ func (test PrecompileTest) setup(t testing.TB, module modules.Module, state *tes
|
||||
blockContext.EXPECT().Number().Return(big.NewInt(0)).AnyTimes()
|
||||
blockContext.EXPECT().Timestamp().Return(uint64(time.Now().Unix())).AnyTimes()
|
||||
}
|
||||
snowContext := utilstest.NewTestSnowContext(t)
|
||||
consensusContext := utilstest.NewTestConsensusContext(t)
|
||||
|
||||
accessibleState := contract.NewMockAccessibleState(ctrl)
|
||||
accessibleState.EXPECT().GetStateDB().Return(state).AnyTimes()
|
||||
accessibleState.EXPECT().GetBlockContext().Return(blockContext).AnyTimes()
|
||||
accessibleState.EXPECT().GetSnowContext().Return(snowContext).AnyTimes()
|
||||
accessibleState.EXPECT().GetConsensusContext().Return(consensusContext).AnyTimes()
|
||||
accessibleState.EXPECT().GetChainConfig().Return(chainConfig).AnyTimes()
|
||||
|
||||
if test.Config != nil {
|
||||
|
||||
+4
-4
@@ -4,15 +4,15 @@
|
||||
|
||||
echo "Reverting import paths for luxfi/node v1.13.4..."
|
||||
|
||||
# Revert consensus imports back to snow
|
||||
# Revert consensus imports back to consensus
|
||||
find . -name "*.go" -type f -exec sed -i.bak \
|
||||
-e 's|"github.com/luxfi/node/consensus/validators"|"github.com/luxfi/node/consensus/validators"|g' \
|
||||
-e 's|"github.com/luxfi/node/consensus/engine/chain"|"github.com/luxfi/node/consensus/consensus/snowman"|g' \
|
||||
-e 's|"github.com/luxfi/node/consensus/engine/chain"|"github.com/luxfi/node/consensus/consensus/chain"|g' \
|
||||
-e 's|"github.com/luxfi/node/consensus/engine/core"|"github.com/luxfi/node/consensus/engine/common"|g' \
|
||||
-e 's|"github.com/luxfi/node/consensus/engine/enginetest"|"github.com/luxfi/node/consensus/engine/enginetest"|g' \
|
||||
-e 's|"github.com/luxfi/node/uptime"|"github.com/luxfi/node/consensus/uptime"|g' \
|
||||
-e 's|"github.com/luxfi/node/consensus/chain/block"|"github.com/luxfi/node/consensus/engine/snowman/block"|g' \
|
||||
-e 's|"github.com/luxfi/node/consensus/chaintest"|"github.com/luxfi/node/consensus/snowtest"|g' \
|
||||
-e 's|"github.com/luxfi/node/consensus/chain/block"|"github.com/luxfi/node/consensus/engine/chain/block"|g' \
|
||||
-e 's|"github.com/luxfi/node/consensus/chaintest"|"github.com/luxfi/node/consensus/consensustest"|g' \
|
||||
-e 's|commonEng "github.com/luxfi/node/consensus/engine/core"|commonEng "github.com/luxfi/node/consensus/engine/common"|g' \
|
||||
-e 's|"github.com/luxfi/node/consensus"|"github.com/luxfi/node/consensus"|g' \
|
||||
{} \;
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@ The above information is called a _state summary_, and each syncable block corre
|
||||
|
||||
1. The engine calls `StateSyncEnabled`. The VM returns `true` to initiate state sync, or `false` to start bootstrapping. In `evm`, this is controlled by the `state-sync-enabled` flag.
|
||||
1. The engine calls `GetOngoingSyncStateSummary`. If the VM has a previously interrupted sync to resume it returns that summary. Otherwise, it returns `ErrNotFound`. By default, `evm` will resume an interrupted sync.
|
||||
1. The engine samples peers for their latest available summaries, then verifies the correctness and availability of each sampled summary with validators. The messaging flow is documented [here](https://github.com/luxfi/luxd/blob/master/snow/engine/snowman/block/README.md).
|
||||
1. The engine samples peers for their latest available summaries, then verifies the correctness and availability of each sampled summary with validators. The messaging flow is documented [here](https://github.com/luxfi/luxd/blob/master/consensus/engine/chain/block/README.md).
|
||||
1. The engine calls `Accept` on the chosen summary. The VM may return `false` to skip syncing to this summary (`evm` skips state sync for less than `defaultStateSyncMinBlocks = 300_000` blocks). If the VM decides to perform the sync, it must return `true` without blocking and fetch the state from its peers asynchronously.
|
||||
1. The VM sends `common.StateSyncDone` on the `toEngine` channel on completion.
|
||||
1. The engine calls `VM.SetState(Bootstrapping)`. Then, blocks after the syncable block are processed one by one.
|
||||
|
||||
@@ -38,7 +38,7 @@ import (
|
||||
"github.com/luxfi/geth/core/rawdb"
|
||||
"github.com/luxfi/geth/core/types"
|
||||
"github.com/luxfi/geth/ethdb"
|
||||
"github.com/luxfi/geth/stateconf"
|
||||
"github.com/luxfi/geth/geth/stateconf"
|
||||
"github.com/luxfi/geth/log"
|
||||
"github.com/luxfi/geth/metrics"
|
||||
"github.com/luxfi/geth/rlp"
|
||||
|
||||
@@ -37,7 +37,7 @@ import (
|
||||
"github.com/luxfi/geth/core/rawdb"
|
||||
"github.com/luxfi/geth/core/types"
|
||||
"github.com/luxfi/geth/ethdb"
|
||||
"github.com/luxfi/geth/stateconf"
|
||||
"github.com/luxfi/geth/geth/stateconf"
|
||||
"github.com/luxfi/geth/log"
|
||||
"github.com/luxfi/geth/trie/trienode"
|
||||
"github.com/luxfi/geth/trie/triestate"
|
||||
|
||||
@@ -126,8 +126,8 @@ func (db *Database) loadJournal(diskRoot common.Hash) (layer, error) {
|
||||
// loadLayers loads a pre-existing state layer backed by a key-value store.
|
||||
func (db *Database) loadLayers() layer {
|
||||
// Retrieve the root node of persistent state.
|
||||
_, root := rawdb.ReadAccountTrieNode(db.diskdb, nil)
|
||||
root = types.TrieRootHash(root)
|
||||
// TODO: Properly get the state root
|
||||
root := common.Hash{}
|
||||
|
||||
// Load the layers by resolving the journal
|
||||
head, err := db.loadJournal(root)
|
||||
|
||||
+17
-17
@@ -29,8 +29,8 @@ func NewTestValidatorState() *validatorstest.State {
|
||||
GetSubnetIDF: func(_ context.Context, chainID ids.ID) (ids.ID, error) {
|
||||
subnetID, ok := map[ids.ID]ids.ID{
|
||||
constants.PlatformChainID: constants.PrimaryNetworkID,
|
||||
snowtest.XChainID: constants.PrimaryNetworkID,
|
||||
snowtest.CChainID: constants.PrimaryNetworkID,
|
||||
consensustest.XChainID: constants.PrimaryNetworkID,
|
||||
consensustest.CChainID: constants.PrimaryNetworkID,
|
||||
SubnetEVMTestChainID: constants.PrimaryNetworkID,
|
||||
}[chainID]
|
||||
if !ok {
|
||||
@@ -47,31 +47,31 @@ func NewTestValidatorState() *validatorstest.State {
|
||||
}
|
||||
}
|
||||
|
||||
// NewTestSnowContext returns a consensus.Context with validator state properly configured for testing.
|
||||
// This wraps snowtest.Context and sets the validator state to avoid the missing GetValidatorSetF issue.
|
||||
// NewTestConsensusContext returns a consensus.Context with validator state properly configured for testing.
|
||||
// This wraps consensustest.Context and sets the validator state to avoid the missing GetValidatorSetF issue.
|
||||
//
|
||||
// Usage example:
|
||||
//
|
||||
// // Instead of:
|
||||
// // snowCtx := utilstest.NewTestSnowContext(t, snowtest.CChainID)
|
||||
// // consensusCtx := utilstest.NewTestConsensusContext(t, consensustest.CChainID)
|
||||
// // validatorState := utils.NewTestValidatorState()
|
||||
// // snowCtx.ValidatorState = validatorState
|
||||
// // consensusCtx.ValidatorState = validatorState
|
||||
//
|
||||
// // Use:
|
||||
// snowCtx := utils.NewTestSnowContext(t)
|
||||
// consensusCtx := utils.NewTestConsensusContext(t)
|
||||
//
|
||||
// This function ensures that the snow context has a properly configured validator state
|
||||
// This function ensures that the consensus context has a properly configured validator state
|
||||
// that includes the GetValidatorSetF function, which is required by many tests.
|
||||
func NewTestSnowContext(t testing.TB) *consensus.Context {
|
||||
snowCtx := snowtest.Context(t, SubnetEVMTestChainID)
|
||||
snowCtx.ValidatorState = NewTestValidatorState()
|
||||
return snowCtx
|
||||
func NewTestConsensusContext(t testing.TB) *consensus.Context {
|
||||
consensusCtx := consensustest.Context(t, SubnetEVMTestChainID)
|
||||
consensusCtx.ValidatorState = NewTestValidatorState()
|
||||
return consensusCtx
|
||||
}
|
||||
|
||||
// NewTestSnowContextWithChainID returns a consensus.Context with validator state properly configured for testing
|
||||
// NewTestConsensusContextWithChainID returns a consensus.Context with validator state properly configured for testing
|
||||
// with a specific chain ID. This is provided for backward compatibility when a specific chain ID is needed.
|
||||
func NewTestSnowContextWithChainID(t testing.TB, chainID ids.ID) *consensus.Context {
|
||||
snowCtx := snowtest.Context(t, chainID)
|
||||
snowCtx.ValidatorState = NewTestValidatorState()
|
||||
return snowCtx
|
||||
func NewTestConsensusContextWithChainID(t testing.TB, chainID ids.ID) *consensus.Context {
|
||||
consensusCtx := consensustest.Context(t, chainID)
|
||||
consensusCtx.ValidatorState = NewTestValidatorState()
|
||||
return consensusCtx
|
||||
}
|
||||
|
||||
@@ -11,13 +11,13 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestNewTestSnowContext(t *testing.T) {
|
||||
// Test that NewTestSnowContext creates a context with validator state
|
||||
snowCtx := NewTestSnowContext(t)
|
||||
require.NotNil(t, snowCtx.ValidatorState)
|
||||
func TestNewTestConsensusContext(t *testing.T) {
|
||||
// Test that NewTestConsensusContext creates a context with validator state
|
||||
consensusCtx := NewTestConsensusContext(t)
|
||||
require.NotNil(t, consensusCtx.ValidatorState)
|
||||
|
||||
// Test that the validator state has the required functions
|
||||
validatorState := snowCtx.ValidatorState
|
||||
validatorState := consensusCtx.ValidatorState
|
||||
require.NotNil(t, validatorState)
|
||||
|
||||
// Test that we can call GetValidatorSetF without panicking
|
||||
|
||||
+3
-2
@@ -11,10 +11,11 @@ import (
|
||||
"github.com/luxfi/node/cache"
|
||||
"github.com/luxfi/node/cache/lru"
|
||||
"github.com/luxfi/node/database"
|
||||
"github.com/luxfi/node/ids"
|
||||
"github.com/luxfi/ids"
|
||||
|
||||
"github.com/luxfi/node/network/p2p/acp118"
|
||||
"github.com/luxfi/node/consensus/chain"
|
||||
"github.com/luxfi/node/consensus/chain"
|
||||
luxWarp "github.com/luxfi/node/vms/platformvm/warp"
|
||||
"github.com/luxfi/node/vms/platformvm/warp/payload"
|
||||
|
||||
@@ -30,7 +31,7 @@ var (
|
||||
)
|
||||
|
||||
type BlockClient interface {
|
||||
GetAcceptedBlock(ctx context.Context, blockID ids.ID) (snowman.Block, error)
|
||||
GetAcceptedBlock(ctx context.Context, blockID ids.ID) (chain.Block, error)
|
||||
}
|
||||
|
||||
// Backend tracks signature-eligible warp messages and provides an interface to fetch them.
|
||||
|
||||
+2
-2
@@ -8,7 +8,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/luxfi/node/ids"
|
||||
"github.com/luxfi/ids"
|
||||
"github.com/luxfi/node/network/p2p/acp118"
|
||||
"github.com/luxfi/node/consensus"
|
||||
"github.com/luxfi/node/vms/platformvm/warp"
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
|
||||
var errNoValidators = errors.New("cannot aggregate signatures from subnet with no validators")
|
||||
|
||||
// API introduces snowman specific functionality to the evm
|
||||
// API introduces chain specific functionality to the evm
|
||||
type API struct {
|
||||
chainContext *consensus.Context
|
||||
backend Backend
|
||||
|
||||
@@ -24,10 +24,10 @@ func TestGetValidatorSetPrimaryNetwork(t *testing.T) {
|
||||
otherSubnetID := ids.GenerateTestID()
|
||||
|
||||
mockState := validatorsmock.NewState(ctrl)
|
||||
snowCtx := utilstest.NewTestSnowContext(t)
|
||||
snowCtx.SubnetID = mySubnetID
|
||||
snowCtx.ValidatorState = mockState
|
||||
state := NewState(snowCtx.ValidatorState, snowCtx.SubnetID, snowCtx.ChainID, false)
|
||||
consensusCtx := utilstest.NewTestConsensusContext(t)
|
||||
consensusCtx.SubnetID = mySubnetID
|
||||
consensusCtx.ValidatorState = mockState
|
||||
state := NewState(consensusCtx.ValidatorState, consensusCtx.SubnetID, consensusCtx.ChainID, false)
|
||||
// Expect that requesting my validator set returns my validator set
|
||||
mockState.EXPECT().GetValidatorSet(gomock.Any(), gomock.Any(), mySubnetID).Return(make(map[ids.NodeID]*validators.GetValidatorOutput), nil)
|
||||
output, err := state.GetValidatorSet(context.Background(), 10, mySubnetID)
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
"github.com/luxfi/node/database"
|
||||
"github.com/luxfi/node/consensus/engine/core"
|
||||
"github.com/luxfi/node/consensus/engine/core/common"
|
||||
luxWarp "github.com/luxfi/node/vms/platformvm/warp"
|
||||
"github.com/luxfi/node/vms/platformvm/warp/payload"
|
||||
)
|
||||
|
||||
@@ -33,13 +33,13 @@ func TestAddressedCallSignatures(t *testing.T) {
|
||||
metricstest.WithMetrics(t)
|
||||
|
||||
database := memdb.New()
|
||||
snowCtx := utilstest.NewTestSnowContext(t)
|
||||
consensusCtx := utilstest.NewTestConsensusContext(t)
|
||||
|
||||
offChainPayload, err := payload.NewAddressedCall([]byte{1, 2, 3}, []byte{1, 2, 3})
|
||||
require.NoError(t, err)
|
||||
offchainMessage, err := luxWarp.NewUnsignedMessage(snowCtx.NetworkID, snowCtx.ChainID, offChainPayload.Bytes())
|
||||
offchainMessage, err := luxWarp.NewUnsignedMessage(consensusCtx.NetworkID, consensusCtx.ChainID, offChainPayload.Bytes())
|
||||
require.NoError(t, err)
|
||||
offchainSignature, err := snowCtx.WarpSigner.Sign(offchainMessage)
|
||||
offchainSignature, err := consensusCtx.WarpSigner.Sign(offchainMessage)
|
||||
require.NoError(t, err)
|
||||
|
||||
tests := map[string]struct {
|
||||
@@ -51,9 +51,9 @@ func TestAddressedCallSignatures(t *testing.T) {
|
||||
setup: func(backend Backend) (request []byte, expectedResponse []byte) {
|
||||
knownPayload, err := payload.NewAddressedCall([]byte{0, 0, 0}, []byte("test"))
|
||||
require.NoError(t, err)
|
||||
msg, err := luxWarp.NewUnsignedMessage(snowCtx.NetworkID, snowCtx.ChainID, knownPayload.Bytes())
|
||||
msg, err := luxWarp.NewUnsignedMessage(consensusCtx.NetworkID, consensusCtx.ChainID, knownPayload.Bytes())
|
||||
require.NoError(t, err)
|
||||
signature, err := snowCtx.WarpSigner.Sign(msg)
|
||||
signature, err := consensusCtx.WarpSigner.Sign(msg)
|
||||
require.NoError(t, err)
|
||||
|
||||
backend.AddMessage(msg)
|
||||
@@ -77,7 +77,7 @@ func TestAddressedCallSignatures(t *testing.T) {
|
||||
setup: func(_ Backend) (request []byte, expectedResponse []byte) {
|
||||
unknownPayload, err := payload.NewAddressedCall([]byte{0, 0, 0}, []byte("unknown message"))
|
||||
require.NoError(t, err)
|
||||
unknownMessage, err := luxWarp.NewUnsignedMessage(snowCtx.NetworkID, snowCtx.ChainID, unknownPayload.Bytes())
|
||||
unknownMessage, err := luxWarp.NewUnsignedMessage(consensusCtx.NetworkID, consensusCtx.ChainID, unknownPayload.Bytes())
|
||||
require.NoError(t, err)
|
||||
return unknownMessage.Bytes(), nil
|
||||
},
|
||||
@@ -104,9 +104,9 @@ func TestAddressedCallSignatures(t *testing.T) {
|
||||
sigCache = &cache.Empty[ids.ID, []byte]{}
|
||||
}
|
||||
warpBackend, err := NewBackend(
|
||||
snowCtx.NetworkID,
|
||||
snowCtx.ChainID,
|
||||
snowCtx.WarpSigner,
|
||||
consensusCtx.NetworkID,
|
||||
consensusCtx.ChainID,
|
||||
consensusCtx.WarpSigner,
|
||||
warptest.EmptyBlockClient,
|
||||
nil,
|
||||
database,
|
||||
@@ -114,7 +114,7 @@ func TestAddressedCallSignatures(t *testing.T) {
|
||||
[][]byte{offchainMessage.Bytes()},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
handler := acp118.NewCachedHandler(sigCache, warpBackend, snowCtx.WarpSigner)
|
||||
handler := acp118.NewCachedHandler(sigCache, warpBackend, consensusCtx.WarpSigner)
|
||||
|
||||
requestBytes, expectedResponse := test.setup(warpBackend)
|
||||
protoMsg := &sdk.SignatureRequest{Message: requestBytes}
|
||||
@@ -155,7 +155,7 @@ func TestBlockSignatures(t *testing.T) {
|
||||
metricstest.WithMetrics(t)
|
||||
|
||||
database := memdb.New()
|
||||
snowCtx := utilstest.NewTestSnowContext(t)
|
||||
consensusCtx := utilstest.NewTestConsensusContext(t)
|
||||
|
||||
knownBlkID := ids.GenerateTestID()
|
||||
blockClient := warptest.MakeBlockClient(knownBlkID)
|
||||
@@ -166,7 +166,7 @@ func TestBlockSignatures(t *testing.T) {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
msg, err := luxWarp.NewUnsignedMessage(snowCtx.NetworkID, snowCtx.ChainID, idPayload.Bytes())
|
||||
msg, err := luxWarp.NewUnsignedMessage(consensusCtx.NetworkID, consensusCtx.ChainID, idPayload.Bytes())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -183,9 +183,9 @@ func TestBlockSignatures(t *testing.T) {
|
||||
setup: func() (request []byte, expectedResponse []byte) {
|
||||
hashPayload, err := payload.NewHash(knownBlkID)
|
||||
require.NoError(t, err)
|
||||
unsignedMessage, err := luxWarp.NewUnsignedMessage(snowCtx.NetworkID, snowCtx.ChainID, hashPayload.Bytes())
|
||||
unsignedMessage, err := luxWarp.NewUnsignedMessage(consensusCtx.NetworkID, consensusCtx.ChainID, hashPayload.Bytes())
|
||||
require.NoError(t, err)
|
||||
signature, err := snowCtx.WarpSigner.Sign(unsignedMessage)
|
||||
signature, err := consensusCtx.WarpSigner.Sign(unsignedMessage)
|
||||
require.NoError(t, err)
|
||||
return toMessageBytes(knownBlkID), signature[:]
|
||||
},
|
||||
@@ -222,9 +222,9 @@ func TestBlockSignatures(t *testing.T) {
|
||||
sigCache = &cache.Empty[ids.ID, []byte]{}
|
||||
}
|
||||
warpBackend, err := NewBackend(
|
||||
snowCtx.NetworkID,
|
||||
snowCtx.ChainID,
|
||||
snowCtx.WarpSigner,
|
||||
consensusCtx.NetworkID,
|
||||
consensusCtx.ChainID,
|
||||
consensusCtx.WarpSigner,
|
||||
blockClient,
|
||||
warptest.NoOpValidatorReader{},
|
||||
database,
|
||||
@@ -232,7 +232,7 @@ func TestBlockSignatures(t *testing.T) {
|
||||
nil,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
handler := acp118.NewCachedHandler(sigCache, warpBackend, snowCtx.WarpSigner)
|
||||
handler := acp118.NewCachedHandler(sigCache, warpBackend, consensusCtx.WarpSigner)
|
||||
|
||||
requestBytes, expectedResponse := test.setup()
|
||||
protoMsg := &sdk.SignatureRequest{Message: requestBytes}
|
||||
@@ -270,14 +270,14 @@ func TestBlockSignatures(t *testing.T) {
|
||||
|
||||
func TestUptimeSignatures(t *testing.T) {
|
||||
database := memdb.New()
|
||||
snowCtx := utilstest.NewTestSnowContext(t)
|
||||
consensusCtx := utilstest.NewTestConsensusContext(t)
|
||||
|
||||
getUptimeMessageBytes := func(sourceAddress []byte, vID ids.ID, totalUptime uint64) ([]byte, *luxWarp.UnsignedMessage) {
|
||||
uptimePayload, err := messages.NewValidatorUptime(vID, 80)
|
||||
require.NoError(t, err)
|
||||
addressedCall, err := payload.NewAddressedCall(sourceAddress, uptimePayload.Bytes())
|
||||
require.NoError(t, err)
|
||||
unsignedMessage, err := luxWarp.NewUnsignedMessage(snowCtx.NetworkID, snowCtx.ChainID, addressedCall.Bytes())
|
||||
unsignedMessage, err := luxWarp.NewUnsignedMessage(consensusCtx.NetworkID, consensusCtx.ChainID, addressedCall.Bytes())
|
||||
require.NoError(t, err)
|
||||
|
||||
protoMsg := &sdk.SignatureRequest{Message: unsignedMessage.Bytes()}
|
||||
@@ -293,7 +293,7 @@ func TestUptimeSignatures(t *testing.T) {
|
||||
} else {
|
||||
sigCache = &cache.Empty[ids.ID, []byte]{}
|
||||
}
|
||||
chainCtx := utilstest.NewTestSnowContext(t)
|
||||
chainCtx := utilstest.NewTestConsensusContext(t)
|
||||
clk := &mockable.Clock{}
|
||||
validatorsManager, err := validators.NewManager(chainCtx, memdb.New(), clk)
|
||||
require.NoError(t, err)
|
||||
@@ -301,9 +301,9 @@ func TestUptimeSignatures(t *testing.T) {
|
||||
newLockedValidatorManager := validators.NewLockedValidatorReader(validatorsManager, lock)
|
||||
validatorsManager.StartTracking([]ids.NodeID{})
|
||||
warpBackend, err := NewBackend(
|
||||
snowCtx.NetworkID,
|
||||
snowCtx.ChainID,
|
||||
snowCtx.WarpSigner,
|
||||
consensusCtx.NetworkID,
|
||||
consensusCtx.ChainID,
|
||||
consensusCtx.WarpSigner,
|
||||
warptest.EmptyBlockClient,
|
||||
newLockedValidatorManager,
|
||||
database,
|
||||
@@ -311,7 +311,7 @@ func TestUptimeSignatures(t *testing.T) {
|
||||
nil,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
handler := acp118.NewCachedHandler(sigCache, warpBackend, snowCtx.WarpSigner)
|
||||
handler := acp118.NewCachedHandler(sigCache, warpBackend, consensusCtx.WarpSigner)
|
||||
|
||||
// sourceAddress nonZero
|
||||
protoBytes, _ := getUptimeMessageBytes([]byte{1, 2, 3}, ids.GenerateTestID(), 80)
|
||||
@@ -355,7 +355,7 @@ func TestUptimeSignatures(t *testing.T) {
|
||||
protoBytes, msg := getUptimeMessageBytes([]byte{}, validationID, 80)
|
||||
responseBytes, appErr := handler.AppRequest(context.Background(), nodeID, time.Time{}, protoBytes)
|
||||
require.Nil(t, appErr)
|
||||
expectedSignature, err := snowCtx.WarpSigner.Sign(msg)
|
||||
expectedSignature, err := consensusCtx.WarpSigner.Sign(msg)
|
||||
require.NoError(t, err)
|
||||
response := &sdk.SignatureResponse{}
|
||||
require.NoError(t, proto.Unmarshal(responseBytes, response))
|
||||
|
||||
@@ -18,9 +18,9 @@ import (
|
||||
// EmptyBlockClient returns an error if a block is requested
|
||||
var EmptyBlockClient BlockClient = MakeBlockClient()
|
||||
|
||||
type BlockClient func(ctx context.Context, blockID ids.ID) (snowman.Block, error)
|
||||
type BlockClient func(ctx context.Context, blockID ids.ID) (chain.Block, error)
|
||||
|
||||
func (f BlockClient) GetAcceptedBlock(ctx context.Context, blockID ids.ID) (snowman.Block, error) {
|
||||
func (f BlockClient) GetAcceptedBlock(ctx context.Context, blockID ids.ID) (chain.Block, error) {
|
||||
return f(ctx, blockID)
|
||||
}
|
||||
|
||||
@@ -28,15 +28,15 @@ func (f BlockClient) GetAcceptedBlock(ctx context.Context, blockID ids.ID) (snow
|
||||
// If a block is requested that isn't part of the provided blocks, an error is
|
||||
// returned.
|
||||
func MakeBlockClient(blkIDs ...ids.ID) BlockClient {
|
||||
return func(_ context.Context, blkID ids.ID) (snowman.Block, error) {
|
||||
return func(_ context.Context, blkID ids.ID) (chain.Block, error) {
|
||||
if !slices.Contains(blkIDs, blkID) {
|
||||
return nil, database.ErrNotFound
|
||||
}
|
||||
|
||||
return &snowmantest.Block{
|
||||
Decidable: snowtest.Decidable{
|
||||
return &chaintest.Block{
|
||||
Decidable: consensustest.Decidable{
|
||||
IDV: blkID,
|
||||
Status: snowtest.Accepted,
|
||||
Status: consensustest.Accepted,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user