├── proto ├── buf.md ├── buf.gen.yaml ├── buf.lock ├── warp │ └── message.proto ├── aliasreader │ └── aliasreader.proto ├── io │ ├── writer │ │ └── writer.proto │ └── reader │ │ └── reader.proto ├── vm │ └── runtime │ │ └── runtime.proto └── signer │ └── signer.proto ├── bin ├── ginkgo ├── tmpnetctl └── avalanchego ├── staking ├── local │ ├── signer1.key │ ├── signer2.key │ ├── signer3.key │ ├── signer4.key │ └── signer5.key ├── large_rsa_key.cert └── certificate.go ├── main └── default.pgo ├── resources └── AvalancheLogoRed.png ├── utils ├── compression │ ├── zstd_zip_bomb.bin │ ├── compressor.go │ ├── no_compressor.go │ └── no_compressor_test.go ├── zero.go ├── perms │ ├── perms.go │ ├── chmod.go │ └── create.go ├── constants │ ├── aliases.go │ ├── memory.go │ └── application.go ├── units │ ├── bytes.go │ └── avax.go ├── resource │ ├── mocks_generate_test.go │ └── no_usage.go ├── hashing │ ├── mocks_generate_test.go │ ├── hasher.go │ └── consistent │ │ └── hashable.go ├── crypto │ ├── keychain │ │ ├── mocks_generate_test.go │ │ └── ledger.go │ ├── bls │ │ ├── signer.go │ │ ├── blstest │ │ │ └── benchmark.go │ │ ├── ciphersuite.go │ │ └── signer │ │ │ └── localsigner │ │ │ └── benchmark_test.go │ └── secp256k1 │ │ └── secp256k1_benchmark_test.go ├── filesystem │ ├── mocks_generate_test.go │ ├── rename.go │ ├── io.go │ └── mock_file.go ├── stacktrace.go ├── math │ ├── meter │ │ └── factory.go │ ├── averager.go │ ├── sync_averager.go │ └── continuous_averager_benchmark_test.go ├── formatting │ ├── prefixed_stringer.go │ ├── int_format.go │ ├── address │ │ └── converter.go │ └── int_format_test.go ├── timer │ ├── meter.go │ ├── timer_test.go │ └── stopped_timer.go ├── dynamicip │ └── no_updater.go ├── sampler │ ├── weighted.go │ ├── uniform_benchmark_test.go │ └── weighted_without_replacement_benchmark_test.go ├── wrappers │ └── errors.go ├── password │ └── hash_test.go ├── iterator │ ├── empty.go │ ├── empty_test.go │ └── iterator.go ├── storage │ ├── storage_openbsd.go │ └── storage_unix.go ├── ulimit │ └── ulimit_windows.go ├── metric │ └── namespace.go ├── slice.go ├── json │ ├── uint8.go │ ├── uint16.go │ ├── uint32.go │ ├── uint64.go │ ├── float32.go │ └── float64.go ├── beacon │ └── beacon.go ├── bloom │ ├── hasher.go │ └── hasher_test.go └── logging │ └── config.go ├── header.yml ├── .github ├── pull_request_template.md ├── actionlint.yml ├── workflows │ ├── debian │ │ └── template │ │ │ └── control │ ├── check-clean-branch.sh │ ├── fuzz.yml │ ├── build-tgz-pkg.sh │ ├── fuzz_merkledb.yml │ ├── labels.yml │ └── buf-push.yml ├── actions │ ├── install-nix │ │ └── action.yml │ ├── upload-tmpnet-artifact │ │ └── action.yml │ ├── run-monitored-tmpnet-cmd │ │ └── output-metrics-url.sh │ └── setup-go-for-project │ │ └── action.yml ├── ISSUE_TEMPLATE │ └── feature_spec.md └── dependabot.yml ├── connectproto ├── buf.gen.yaml ├── buf.lock ├── xsvm │ └── service.proto └── proposervm │ └── service.proto ├── .dockerignore ├── tests ├── e2e │ ├── c │ │ ├── consume_gas.sol │ │ └── consume_gas.go │ └── ignore.go ├── load │ └── contracts │ │ ├── generate.go │ │ └── TrieStressTest.sol ├── antithesis │ ├── xsvm │ │ └── Dockerfile.config │ ├── avalanchego │ │ ├── Dockerfile.config │ │ └── gencomposeconfig │ │ │ └── main.go │ └── Dockerfile.builder-uninstrumented └── fixture │ └── tmpnet │ ├── detached_process_windows.go │ ├── detached_process_default.go │ └── flags │ └── common.go ├── scripts ├── run_ginkgo.sh ├── run_tool.sh ├── run_avalanchego.sh ├── run_tmpnetctl.sh ├── run_task.sh ├── build_antithesis_xsvm_workload.sh ├── build_antithesis_avalanchego_workload.sh ├── image_tag.sh ├── tests.e2e.bootstrap_monitor.sh ├── build_tmpnetctl.sh ├── git_commit.sh ├── build_bootstrap_monitor.sh ├── shellcheck.sh ├── start_kind_cluster.sh └── actionlint.sh ├── vms ├── example │ └── xsvm │ │ ├── tx │ │ ├── unsigned.go │ │ ├── visitor.go │ │ ├── import.go │ │ ├── codec.go │ │ ├── transfer.go │ │ └── export.go │ │ ├── block │ │ └── codec.go │ │ ├── constants.go │ │ ├── genesis │ │ └── codec.go │ │ ├── factory.go │ │ ├── cmd │ │ ├── chain │ │ │ └── cmd.go │ │ ├── run │ │ │ └── cmd.go │ │ ├── issue │ │ │ ├── cmd.go │ │ │ └── status │ │ │ │ └── status.go │ │ └── version │ │ │ └── cmd.go │ │ ├── state │ │ └── keys.go │ │ └── warp.go ├── fx │ └── factory.go ├── avm │ ├── block │ │ ├── mocks_generate_test.go │ │ └── executor │ │ │ └── mocks_generate_test.go │ ├── health.go │ ├── txs │ │ ├── mocks_generate_test.go │ │ ├── mempool │ │ │ └── mempool.go │ │ ├── txstest │ │ │ └── context.go │ │ └── executor │ │ │ └── backend.go │ ├── metrics │ │ └── mocks_generate_test.go │ ├── state │ │ ├── versions.go │ │ └── mocks_generate_test.go │ ├── config │ │ └── config.go │ ├── factory.go │ ├── config.md │ └── config.go ├── platformvm │ ├── block │ │ ├── mocks_generate_test.go │ │ ├── builder │ │ │ └── main_test.go │ │ ├── executor │ │ │ └── mocks_generate_test.go │ │ ├── parse.go │ │ └── visitor.go │ ├── fx │ │ └── mocks_generate_test.go │ ├── state │ │ ├── staker_status.go │ │ ├── versions.go │ │ └── mocks_generate_test.go │ ├── main_test.go │ ├── network │ │ └── main_test.go │ ├── genesis │ │ └── codec.go │ ├── utxo │ │ └── mocks_generate_test.go │ ├── signer │ │ ├── mocks_generate_test.go │ │ ├── empty.go │ │ ├── empty_test.go │ │ └── signer.go │ ├── warp │ │ ├── message │ │ │ ├── README.md │ │ │ ├── codec.go │ │ │ └── l1_validator_registration_test.go │ │ ├── constants.go │ │ ├── codec.go │ │ └── payload │ │ │ └── codec.go │ ├── txs │ │ ├── fee │ │ │ ├── calculator.go │ │ │ └── simple_calculator.go │ │ ├── convert_subnet_to_l1_tx_test_simple.json │ │ └── subnet_validator_test.go │ └── factory.go ├── proposervm │ ├── mocks_generate_test.go │ ├── main_test.go │ ├── proposer │ │ ├── mocks_generate_test.go │ │ └── validators.go │ ├── block │ │ ├── header_test.go │ │ ├── codec.go │ │ └── header.go │ ├── state │ │ ├── codec.go │ │ └── state_test.go │ ├── summary │ │ ├── codec.go │ │ ├── parse.go │ │ ├── build_test.go │ │ └── build.go │ └── config.go ├── nftfx │ ├── credential.go │ ├── factory_test.go │ ├── credential_test.go │ ├── mint_output_test.go │ └── factory.go ├── propertyfx │ ├── credential.go │ ├── factory_test.go │ ├── credential_test.go │ ├── mint_output.go │ ├── mint_output_test.go │ ├── owned_output.go │ ├── owned_output_test.go │ ├── burn_operation.go │ └── factory.go ├── components │ ├── verify │ │ ├── mocks_generate_test.go │ │ ├── verification_test.go │ │ └── verification.go │ └── avax │ │ ├── mocks_generate_test.go │ │ ├── state.go │ │ ├── utxo.go │ │ └── utxo_handler.go ├── secp256k1fx │ ├── factory_test.go │ ├── tx.go │ ├── mint_output.go │ ├── factory.go │ └── transfer_input.go ├── mocks_generate_test.go ├── registry │ └── mocks_generate_test.go ├── evm │ └── metrics │ │ ├── prometheus │ │ ├── interfaces.go │ │ └── enabled_test.go │ │ └── metricstest │ │ └── metrics.go ├── metervm │ └── metrics.go ├── rpcchainvm │ ├── runtime │ │ └── subprocess │ │ │ ├── non_linux_stopper.go │ │ │ └── stopper.go │ └── gruntime │ │ └── runtime_client.go └── tracedvm │ └── build_block_with_context_vm.go ├── network ├── throttling │ ├── release_func.go │ └── no_inbound_msg_throttler.go ├── conn_test.go ├── p2p │ └── node_sampler.go └── handler_test.go ├── .editorconfig ├── x ├── README.md ├── sync │ ├── db.go │ └── protoutils │ │ └── utils.go ├── archivedb │ └── value.go ├── merkledb │ ├── tracer.go │ ├── batch.go │ ├── wait_group.go │ └── wait_group_test.go └── blockdb │ └── errors.go ├── snow ├── consensus │ ├── snowman │ │ ├── factory.go │ │ ├── mocks_generate_test.go │ │ ├── topological_test.go │ │ ├── bootstrapper │ │ │ ├── poll_test.go │ │ │ ├── noop_test.go │ │ │ └── noop.go │ │ ├── snowmantest │ │ │ └── require.go │ │ └── oracle_block.go │ ├── snowstorm │ │ └── test_tx.go │ └── snowball │ │ └── binary_slush.go ├── engine │ ├── common │ │ ├── mocks_generate_test.go │ │ ├── fx.go │ │ ├── bootstrapable.go │ │ ├── request.go │ │ ├── halter.go │ │ ├── request_test.go │ │ ├── state_syncer.go │ │ ├── bootstrap_tracker.go │ │ └── traced_state_syncer.go │ ├── avalanche │ │ ├── bootstrap │ │ │ └── queue │ │ │ │ ├── parser.go │ │ │ │ ├── job.go │ │ │ │ └── parser_test.go │ │ └── vertex │ │ │ ├── manager.go │ │ │ ├── mocks_generate_test.go │ │ │ ├── vertextest │ │ │ └── manager.go │ │ │ └── storage.go │ └── enginetest │ │ └── timer.go ├── networking │ ├── router │ │ ├── main_test.go │ │ └── mocks_generate_test.go │ ├── timeout │ │ ├── main_test.go │ │ └── mocks_generate_test.go │ ├── handler │ │ ├── mocks_generate_test.go │ │ └── parser.go │ ├── sender │ │ ├── mocks_generate_test.go │ │ └── external_sender.go │ ├── tracker │ │ └── mocks_generate_test.go │ └── benchlist │ │ └── benchable.go ├── validators │ ├── mocks_generate_test.go │ └── connector.go ├── uptime │ ├── mocks_generate_test.go │ └── no_op_calculator.go ├── snowtest │ └── status.go └── state.go ├── codec ├── general_codec.go ├── mocks_generate_test.go ├── registry.go ├── linearcodec │ └── codec_test.go └── hierarchycodec │ └── codec_test.go ├── database ├── errors.go ├── mocks_generate_test.go ├── linkeddb │ ├── codec.go │ └── db_test.go ├── rpcdb │ └── errors.go └── common.go ├── tools.go ├── chains ├── atomic │ ├── mocks_generate_test.go │ ├── codec.go │ └── writer.go └── registrant.go ├── .linkspector.yml ├── .vscode └── settings.json ├── version ├── version_test.go ├── constants_test.go └── string_test.go ├── trace └── noop.go ├── subnets └── no_op_allower.go ├── ids └── request_id.go ├── config └── node │ └── process_context.go ├── message └── mocks_generate_test.go ├── indexer ├── codec.go └── container.go ├── api ├── metrics │ ├── gatherer_test.go │ └── service.md ├── health │ └── checker.go └── admin │ └── key_value_reader.go ├── simplex └── codec.go ├── cache ├── empty.go └── cache.go ├── genesis └── bootstrappers_test.go ├── flake.lock └── wallet └── chain └── x └── builder └── constants.go /proto/buf.md: -------------------------------------------------------------------------------- 1 | README.md -------------------------------------------------------------------------------- /bin/ginkgo: -------------------------------------------------------------------------------- 1 | ../scripts/run_ginkgo.sh -------------------------------------------------------------------------------- /bin/tmpnetctl: -------------------------------------------------------------------------------- 1 | ../scripts/run_tmpnetctl.sh -------------------------------------------------------------------------------- /bin/avalanchego: -------------------------------------------------------------------------------- 1 | ../scripts/run_avalanchego.sh -------------------------------------------------------------------------------- /staking/local/signer1.key: -------------------------------------------------------------------------------- 1 | AvalancheLocalNetworkValidator01 -------------------------------------------------------------------------------- /staking/local/signer2.key: -------------------------------------------------------------------------------- 1 | AvalancheLocalNetworkValidator02 -------------------------------------------------------------------------------- /staking/local/signer3.key: -------------------------------------------------------------------------------- 1 | AvalancheLocalNetworkValidator03 -------------------------------------------------------------------------------- /staking/local/signer4.key: -------------------------------------------------------------------------------- 1 | AvalancheLocalNetworkValidator04 -------------------------------------------------------------------------------- /staking/local/signer5.key: -------------------------------------------------------------------------------- 1 | AvalancheLocalNetworkValidator05 -------------------------------------------------------------------------------- /main/default.pgo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CashRussell/cosmic-lab/HEAD/main/default.pgo -------------------------------------------------------------------------------- /staking/large_rsa_key.cert: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CashRussell/cosmic-lab/HEAD/staking/large_rsa_key.cert -------------------------------------------------------------------------------- /resources/AvalancheLogoRed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CashRussell/cosmic-lab/HEAD/resources/AvalancheLogoRed.png -------------------------------------------------------------------------------- /utils/compression/zstd_zip_bomb.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CashRussell/cosmic-lab/HEAD/utils/compression/zstd_zip_bomb.bin -------------------------------------------------------------------------------- /header.yml: -------------------------------------------------------------------------------- 1 | header: | 2 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 3 | // See the file LICENSE for licensing terms. 4 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | ## Why this should be merged 2 | 3 | ## How this works 4 | 5 | ## How this was tested 6 | 7 | ## Need to be documented in RELEASES.md? 8 | -------------------------------------------------------------------------------- /proto/buf.gen.yaml: -------------------------------------------------------------------------------- 1 | version: v1 2 | plugins: 3 | - name: go 4 | out: pb 5 | opt: paths=source_relative 6 | - name: go-grpc 7 | out: pb 8 | opt: paths=source_relative 9 | -------------------------------------------------------------------------------- /.github/actionlint.yml: -------------------------------------------------------------------------------- 1 | self-hosted-runner: 2 | labels: 3 | - custom-arm64-jammy 4 | - custom-arm64-noble 5 | - avalanche-avalanchego-runner # Github Action Runner Controller 6 | -------------------------------------------------------------------------------- /connectproto/buf.gen.yaml: -------------------------------------------------------------------------------- 1 | version: v1 2 | plugins: 3 | - name: go 4 | out: pb 5 | opt: paths=source_relative 6 | - plugin: connect-go 7 | out: pb 8 | opt: paths=source_relative 9 | -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | .ci 2 | .github 3 | .gitignore 4 | .golangci.yml 5 | 6 | .idea 7 | .vscode 8 | 9 | LICENSE 10 | *.md 11 | 12 | # Ignore all dockerfiles not just the main one 13 | Dockerfile* 14 | -------------------------------------------------------------------------------- /tests/e2e/c/consume_gas.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity = 0.8.6; 4 | 5 | contract ConsumeGas { 6 | function run() public { 7 | while (true){} 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /proto/buf.lock: -------------------------------------------------------------------------------- 1 | # Generated by buf. DO NOT EDIT. 2 | version: v1 3 | deps: 4 | - remote: buf.build 5 | owner: prometheus 6 | repository: client-model 7 | commit: 1d56a02d481a412a83b3c4984eb90c2e 8 | -------------------------------------------------------------------------------- /scripts/run_ginkgo.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | 5 | AVALANCHE_PATH=$(cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd ) 6 | "${AVALANCHE_PATH}"/scripts/run_tool.sh ginkgo "${@}" 7 | -------------------------------------------------------------------------------- /scripts/run_tool.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | 5 | AVALANCHE_PATH="$(cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd )" 6 | go tool -modfile="${AVALANCHE_PATH}"/tools/go.mod "${@}" 7 | -------------------------------------------------------------------------------- /connectproto/buf.lock: -------------------------------------------------------------------------------- 1 | # Generated by buf. DO NOT EDIT. 2 | version: v1 3 | deps: 4 | - remote: buf.build 5 | owner: prometheus 6 | repository: client-model 7 | commit: 1d56a02d481a412a83b3c4984eb90c2e 8 | -------------------------------------------------------------------------------- /tests/load/contracts/generate.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package contracts 5 | 6 | //go:generate ./generate_abi_bindings.sh 7 | -------------------------------------------------------------------------------- /tests/antithesis/xsvm/Dockerfile.config: -------------------------------------------------------------------------------- 1 | FROM scratch AS execution 2 | 3 | # Copy config artifacts from the build path. For simplicity, artifacts 4 | # are built outside of the docker image. 5 | COPY ./build/antithesis/xsvm/ / 6 | -------------------------------------------------------------------------------- /vms/example/xsvm/tx/unsigned.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package tx 5 | 6 | type Unsigned interface { 7 | Visit(Visitor) error 8 | } 9 | -------------------------------------------------------------------------------- /network/throttling/release_func.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package throttling 5 | 6 | type ReleaseFunc func() 7 | 8 | func noopRelease() {} 9 | -------------------------------------------------------------------------------- /tests/antithesis/avalanchego/Dockerfile.config: -------------------------------------------------------------------------------- 1 | FROM scratch AS execution 2 | 3 | # Copy config artifacts from the build path. For simplicity, artifacts 4 | # are built outside of the docker image. 5 | COPY ./build/antithesis/avalanchego/ / 6 | -------------------------------------------------------------------------------- /utils/zero.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package utils 5 | 6 | // Returns a new instance of a T. 7 | func Zero[T any]() (_ T) { 8 | return 9 | } 10 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # https://editorconfig.org/ 2 | root = true 3 | 4 | [*] 5 | end_of_line = lf 6 | insert_final_newline = true 7 | trim_trailing_whitespace = true 8 | 9 | indent_style = space 10 | indent_size = 2 11 | 12 | [*.go] 13 | indent_style = tab 14 | -------------------------------------------------------------------------------- /.github/workflows/debian/template/control: -------------------------------------------------------------------------------- 1 | Package: avalanchego 2 | Version: 0.1.0 3 | Section: misc 4 | Priority: optional 5 | Architecture: arm64 6 | Depends: 7 | Maintainer: Stephen Buttolph 8 | Description: The Avalanche platform binaries 9 | -------------------------------------------------------------------------------- /vms/fx/factory.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package fx 5 | 6 | // Factory returns an instance of a feature extension 7 | type Factory interface { 8 | New() any 9 | } 10 | -------------------------------------------------------------------------------- /utils/perms/perms.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package perms 5 | 6 | const ( 7 | ReadOnly = 0o400 8 | ReadWrite = 0o640 9 | ReadWriteExecute = 0o750 10 | ) 11 | -------------------------------------------------------------------------------- /vms/avm/block/mocks_generate_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package block 5 | 6 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE} -destination=mock_block.go . Block 7 | -------------------------------------------------------------------------------- /x/README.md: -------------------------------------------------------------------------------- 1 | # `x` Package 2 | 3 | This package contains experimental code that may be moved to other packages in the future. Code in this package is not stable and may be moved, removed or modified at any time. This code should not be relied on for correctness in important applications. -------------------------------------------------------------------------------- /snow/consensus/snowman/factory.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package snowman 5 | 6 | // Factory returns new instances of Consensus 7 | type Factory interface { 8 | New() Consensus 9 | } 10 | -------------------------------------------------------------------------------- /staking/certificate.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package staking 5 | 6 | import "crypto" 7 | 8 | type Certificate struct { 9 | Raw []byte 10 | PublicKey crypto.PublicKey 11 | } 12 | -------------------------------------------------------------------------------- /vms/platformvm/block/mocks_generate_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package block 5 | 6 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE} -destination=mock_block.go . Block 7 | -------------------------------------------------------------------------------- /utils/constants/aliases.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package constants 5 | 6 | // ChainAliasPrefix denotes a prefix for an alias that belongs to a blockchain ID. 7 | const ChainAliasPrefix string = "bc" 8 | -------------------------------------------------------------------------------- /utils/units/bytes.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package units 5 | 6 | const ( 7 | KiB = 1024 // 1 kibibyte 8 | MiB = 1024 * KiB // 1 mebibyte 9 | GiB = 1024 * MiB // 1 gibibyte 10 | ) 11 | -------------------------------------------------------------------------------- /vms/example/xsvm/tx/visitor.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package tx 5 | 6 | type Visitor interface { 7 | Transfer(*Transfer) error 8 | Export(*Export) error 9 | Import(*Import) error 10 | } 11 | -------------------------------------------------------------------------------- /vms/proposervm/mocks_generate_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package proposervm 5 | 6 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE} -destination=mocks_test.go . PostForkBlock 7 | -------------------------------------------------------------------------------- /utils/constants/memory.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package constants 5 | 6 | // PointerOverhead is used to approximate the memory footprint from allocating a 7 | // pointer. 8 | const PointerOverhead = 8 9 | -------------------------------------------------------------------------------- /codec/general_codec.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package codec 5 | 6 | // GeneralCodec marshals and unmarshals structs including interfaces 7 | type GeneralCodec interface { 8 | Codec 9 | Registry 10 | } 11 | -------------------------------------------------------------------------------- /vms/platformvm/fx/mocks_generate_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package fx 5 | 6 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE}mock -destination=${GOPACKAGE}mock/fx.go -mock_names=Fx=Fx . Fx 7 | -------------------------------------------------------------------------------- /vms/avm/health.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package avm 5 | 6 | import "context" 7 | 8 | // TODO: add health checks 9 | func (*VM) HealthCheck(context.Context) (interface{}, error) { 10 | return nil, nil 11 | } 12 | -------------------------------------------------------------------------------- /vms/platformvm/state/staker_status.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package state 5 | 6 | const ( 7 | unmodified diffValidatorStatus = iota 8 | added 9 | deleted 10 | ) 11 | 12 | type diffValidatorStatus uint8 13 | -------------------------------------------------------------------------------- /codec/mocks_generate_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package codec 5 | 6 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE}mock -destination=${GOPACKAGE}mock/manager.go -mock_names=Manager=Manager . Manager 7 | -------------------------------------------------------------------------------- /database/errors.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package database 5 | 6 | import "errors" 7 | 8 | // common errors 9 | var ( 10 | ErrClosed = errors.New("closed") 11 | ErrNotFound = errors.New("not found") 12 | ) 13 | -------------------------------------------------------------------------------- /utils/resource/mocks_generate_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package resource 5 | 6 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE}mock -destination=${GOPACKAGE}mock/user.go -mock_names=User=User . User 7 | -------------------------------------------------------------------------------- /vms/example/xsvm/block/codec.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package block 5 | 6 | import "github.com/ava-labs/avalanchego/vms/example/xsvm/tx" 7 | 8 | const CodecVersion = tx.CodecVersion 9 | 10 | var Codec = tx.Codec 11 | -------------------------------------------------------------------------------- /vms/nftfx/credential.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package nftfx 5 | 6 | import "github.com/ava-labs/avalanchego/vms/secp256k1fx" 7 | 8 | type Credential struct { 9 | secp256k1fx.Credential `serialize:"true"` 10 | } 11 | -------------------------------------------------------------------------------- /vms/example/xsvm/constants.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package xsvm 5 | 6 | import "github.com/ava-labs/avalanchego/version" 7 | 8 | var Version = &version.Semantic{ 9 | Major: 1, 10 | Minor: 0, 11 | Patch: 4, 12 | } 13 | -------------------------------------------------------------------------------- /vms/platformvm/main_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package platformvm 5 | 6 | import ( 7 | "testing" 8 | 9 | "go.uber.org/goleak" 10 | ) 11 | 12 | func TestMain(m *testing.M) { 13 | goleak.VerifyTestMain(m) 14 | } 15 | -------------------------------------------------------------------------------- /vms/proposervm/main_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package proposervm 5 | 6 | import ( 7 | "testing" 8 | 9 | "go.uber.org/goleak" 10 | ) 11 | 12 | func TestMain(m *testing.M) { 13 | goleak.VerifyTestMain(m) 14 | } 15 | -------------------------------------------------------------------------------- /.github/workflows/check-clean-branch.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | 5 | git add --all 6 | git update-index --really-refresh >> /dev/null 7 | 8 | # Show the status of the working tree. 9 | git status --short 10 | 11 | # Exits if any uncommitted changes are found. 12 | git diff-index --quiet HEAD 13 | -------------------------------------------------------------------------------- /snow/engine/common/mocks_generate_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package common 5 | 6 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE}mock -destination=${GOPACKAGE}mock/sender.go -mock_names=Sender=Sender . Sender 7 | -------------------------------------------------------------------------------- /snow/networking/router/main_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package router 5 | 6 | import ( 7 | "testing" 8 | 9 | "go.uber.org/goleak" 10 | ) 11 | 12 | func TestMain(m *testing.M) { 13 | goleak.VerifyTestMain(m) 14 | } 15 | -------------------------------------------------------------------------------- /snow/networking/timeout/main_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package timeout 5 | 6 | import ( 7 | "testing" 8 | 9 | "go.uber.org/goleak" 10 | ) 11 | 12 | func TestMain(m *testing.M) { 13 | goleak.VerifyTestMain(m) 14 | } 15 | -------------------------------------------------------------------------------- /snow/validators/mocks_generate_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package validators 5 | 6 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE}mock -destination=${GOPACKAGE}mock/state.go -mock_names=State=State . State 7 | -------------------------------------------------------------------------------- /utils/hashing/mocks_generate_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package hashing 5 | 6 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE}mock -destination=${GOPACKAGE}mock/hasher.go -mock_names=Hasher=Hasher . Hasher 7 | -------------------------------------------------------------------------------- /vms/avm/txs/mocks_generate_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package txs 5 | 6 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE}mock -destination=${GOPACKAGE}mock/tx.go -mock_names=UnsignedTx=UnsignedTx . UnsignedTx 7 | -------------------------------------------------------------------------------- /vms/platformvm/network/main_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package network 5 | 6 | import ( 7 | "testing" 8 | 9 | "go.uber.org/goleak" 10 | ) 11 | 12 | func TestMain(m *testing.M) { 13 | goleak.VerifyTestMain(m) 14 | } 15 | -------------------------------------------------------------------------------- /vms/propertyfx/credential.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package propertyfx 5 | 6 | import "github.com/ava-labs/avalanchego/vms/secp256k1fx" 7 | 8 | type Credential struct { 9 | secp256k1fx.Credential `serialize:"true"` 10 | } 11 | -------------------------------------------------------------------------------- /snow/consensus/snowman/mocks_generate_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package snowman 5 | 6 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE}mock -destination=${GOPACKAGE}mock/block.go -mock_names=Block=Block . Block 7 | -------------------------------------------------------------------------------- /snow/networking/router/mocks_generate_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package router 5 | 6 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE}mock -destination=${GOPACKAGE}mock/router.go -mock_names=Router=Router . Router 7 | -------------------------------------------------------------------------------- /utils/crypto/keychain/mocks_generate_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package keychain 5 | 6 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE}mock -destination=${GOPACKAGE}mock/ledger.go -mock_names=Ledger=Ledger . Ledger 7 | -------------------------------------------------------------------------------- /utils/filesystem/mocks_generate_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package filesystem 5 | 6 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE}mock -destination=${GOPACKAGE}mock/reader.go -mock_names=Reader=Reader . Reader 7 | -------------------------------------------------------------------------------- /vms/avm/metrics/mocks_generate_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package metrics 5 | 6 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE}mock -destination=${GOPACKAGE}mock/metrics.go -mock_names=Metrics=Metrics . Metrics 7 | -------------------------------------------------------------------------------- /vms/example/xsvm/genesis/codec.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package genesis 5 | 6 | import "github.com/ava-labs/avalanchego/vms/example/xsvm/block" 7 | 8 | const CodecVersion = block.CodecVersion 9 | 10 | var Codec = block.Codec 11 | -------------------------------------------------------------------------------- /vms/platformvm/block/builder/main_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package builder 5 | 6 | import ( 7 | "testing" 8 | 9 | "go.uber.org/goleak" 10 | ) 11 | 12 | func TestMain(m *testing.M) { 13 | goleak.VerifyTestMain(m) 14 | } 15 | -------------------------------------------------------------------------------- /snow/networking/handler/mocks_generate_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package handler 5 | 6 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE}mock -destination=${GOPACKAGE}mock/handler.go -mock_names=Handler=Handler . Handler 7 | -------------------------------------------------------------------------------- /snow/networking/timeout/mocks_generate_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package timeout 5 | 6 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE}mock -destination=${GOPACKAGE}mock/manager.go -mock_names=Manager=Manager . Manager 7 | -------------------------------------------------------------------------------- /snow/uptime/mocks_generate_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package uptime 5 | 6 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE}mock -destination=${GOPACKAGE}mock/calculator.go -mock_names=Calculator=Calculator . Calculator 7 | -------------------------------------------------------------------------------- /utils/stacktrace.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package utils 5 | 6 | import "runtime" 7 | 8 | func GetStacktrace(all bool) string { 9 | buf := make([]byte, 1<<16) 10 | n := runtime.Stack(buf, all) 11 | return string(buf[:n]) 12 | } 13 | -------------------------------------------------------------------------------- /vms/avm/block/executor/mocks_generate_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package executor 5 | 6 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE}mock -destination=${GOPACKAGE}mock/manager.go -mock_names=Manager=Manager . Manager 7 | -------------------------------------------------------------------------------- /vms/platformvm/genesis/codec.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package genesis 5 | 6 | import "github.com/ava-labs/avalanchego/vms/platformvm/block" 7 | 8 | const CodecVersion = block.CodecVersion 9 | 10 | var Codec = block.GenesisCodec 11 | -------------------------------------------------------------------------------- /vms/platformvm/utxo/mocks_generate_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package utxo 5 | 6 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE}mock -destination=${GOPACKAGE}mock/verifier.go -mock_names=Verifier=Verifier . Verifier 7 | -------------------------------------------------------------------------------- /scripts/run_avalanchego.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | 5 | AVALANCHE_PATH=$(cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd ) 6 | cd "${AVALANCHE_PATH}" 7 | 8 | # Build the binary before execution to ensure it is always up-to-date. Faster than `go run`. 9 | ./scripts/build.sh 10 | ./build/avalanchego "${@}" 11 | -------------------------------------------------------------------------------- /snow/engine/common/fx.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package common 5 | 6 | import "github.com/ava-labs/avalanchego/ids" 7 | 8 | // Fx wraps an instance of a feature extension 9 | type Fx struct { 10 | ID ids.ID 11 | Fx interface{} 12 | } 13 | -------------------------------------------------------------------------------- /tools.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package avalanchego 5 | 6 | import ( 7 | _ "github.com/StephenButtolph/canoto/generate" 8 | _ "golang.org/x/mod/semver" // golang.org/x/mod to satisfy requirement for go.uber.org/mock/mockgen@v0.5 9 | ) 10 | -------------------------------------------------------------------------------- /vms/platformvm/signer/mocks_generate_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package signer 5 | 6 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE}mock -source=signer.go -destination=${GOPACKAGE}mock/signer.go -mock_names=Signer=Signer 7 | -------------------------------------------------------------------------------- /vms/proposervm/proposer/mocks_generate_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package proposer 5 | 6 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE}mock -destination=${GOPACKAGE}mock/windower.go -mock_names=Windower=Windower . Windower 7 | -------------------------------------------------------------------------------- /chains/atomic/mocks_generate_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package atomic 5 | 6 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE}mock -destination=${GOPACKAGE}mock/shared_memory.go -mock_names=SharedMemory=SharedMemory . SharedMemory 7 | -------------------------------------------------------------------------------- /scripts/run_tmpnetctl.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | 5 | AVALANCHE_PATH=$(cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd ) 6 | cd "${AVALANCHE_PATH}" 7 | 8 | # Build the binary before execution to ensure it is always up-to-date. Faster than `go run`. 9 | ./scripts/build_tmpnetctl.sh 10 | ./build/tmpnetctl "${@}" 11 | -------------------------------------------------------------------------------- /vms/components/verify/mocks_generate_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package verify 5 | 6 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE}mock -destination=${GOPACKAGE}mock/verifiable.go -mock_names=Verifiable=Verifiable . Verifiable 7 | -------------------------------------------------------------------------------- /vms/platformvm/block/executor/mocks_generate_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package executor 5 | 6 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE}mock -destination=${GOPACKAGE}mock/manager.go -mock_names=Manager=Manager . Manager 7 | -------------------------------------------------------------------------------- /snow/engine/avalanche/bootstrap/queue/parser.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package queue 5 | 6 | import "context" 7 | 8 | // Parser allows parsing a job from bytes. 9 | type Parser interface { 10 | Parse(context.Context, []byte) (Job, error) 11 | } 12 | -------------------------------------------------------------------------------- /utils/crypto/bls/signer.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package bls 5 | 6 | type Signer interface { 7 | PublicKey() *PublicKey 8 | Sign(msg []byte) (*Signature, error) 9 | SignProofOfPossession(msg []byte) (*Signature, error) 10 | Shutdown() error 11 | } 12 | -------------------------------------------------------------------------------- /.linkspector.yml: -------------------------------------------------------------------------------- 1 | dirs: 2 | - . 3 | excludedFiles: 4 | - RELEASES.md # This file has too many links to efficiently check 5 | ignorePatterns: 6 | - pattern: '^http://localhost.*$' # Localhost links are used during tutorials 7 | - pattern: "^https://.+\\.avax-dev\\.network$" # This check doesn't have the correct credentials 8 | useGitIgnore: true 9 | -------------------------------------------------------------------------------- /vms/components/avax/mocks_generate_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package avax 5 | 6 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE}mock -destination=${GOPACKAGE}mock/transferable_in.go -mock_names=TransferableIn=TransferableIn . TransferableIn 7 | -------------------------------------------------------------------------------- /snow/networking/sender/mocks_generate_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package sender 5 | 6 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE}mock -destination=${GOPACKAGE}mock/external_sender.go -mock_names=ExternalSender=ExternalSender . ExternalSender 7 | -------------------------------------------------------------------------------- /tests/fixture/tmpnet/detached_process_windows.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | //go:build windows 5 | 6 | package tmpnet 7 | 8 | import "os/exec" 9 | 10 | func configureDetachedProcess(*exec.Cmd) { 11 | panic("tmpnet deployment to windows is not supported") 12 | } 13 | -------------------------------------------------------------------------------- /utils/math/meter/factory.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package meter 5 | 6 | import "time" 7 | 8 | // Factory returns new meters. 9 | type Factory interface { 10 | // New returns a new meter with the provided halflife. 11 | New(halflife time.Duration) Meter 12 | } 13 | -------------------------------------------------------------------------------- /snow/engine/avalanche/vertex/manager.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package vertex 5 | 6 | // Manager defines all the vertex related functionality that is required by the 7 | // consensus engine. 8 | type Manager interface { 9 | Builder 10 | Parser 11 | Storage 12 | } 13 | -------------------------------------------------------------------------------- /snow/engine/avalanche/vertex/mocks_generate_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package vertex 5 | 6 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE}mock -destination=${GOPACKAGE}mock/linearizable_vm.go -mock_names=LinearizableVM=LinearizableVM . LinearizableVM 7 | -------------------------------------------------------------------------------- /scripts/run_task.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | 5 | # Assume the system-installed task is compatible with the taskfile version 6 | if command -v task > /dev/null 2>&1; then 7 | exec task "${@}" 8 | else 9 | AVALANCHE_PATH="$(cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd )" 10 | "${AVALANCHE_PATH}"/scripts/run_tool.sh task "${@}" 11 | fi 12 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "gopls": { 3 | "build.buildFlags": [ 4 | // Context: https://github.com/ava-labs/avalanchego/pull/3173 5 | // Without this tag, the language server won't build the test-only 6 | // code in non-_test.go files. 7 | "--tags='test'", 8 | ], 9 | }, 10 | "go.testTags": "test", 11 | } -------------------------------------------------------------------------------- /snow/engine/common/bootstrapable.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package common 5 | 6 | import "context" 7 | 8 | type BootstrapableEngine interface { 9 | Engine 10 | 11 | // Clear removes all containers to be processed upon bootstrapping 12 | Clear(ctx context.Context) error 13 | } 14 | -------------------------------------------------------------------------------- /utils/formatting/prefixed_stringer.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package formatting 5 | 6 | import "fmt" 7 | 8 | // PrefixedStringer extends a stringer that adds a prefix 9 | type PrefixedStringer interface { 10 | fmt.Stringer 11 | 12 | PrefixedString(prefix string) string 13 | } 14 | -------------------------------------------------------------------------------- /x/sync/db.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package sync 5 | 6 | import "github.com/ava-labs/avalanchego/x/merkledb" 7 | 8 | type DB interface { 9 | merkledb.Clearer 10 | merkledb.MerkleRootGetter 11 | merkledb.ProofGetter 12 | merkledb.ChangeProofer 13 | merkledb.RangeProofer 14 | } 15 | -------------------------------------------------------------------------------- /utils/hashing/hasher.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package hashing 5 | 6 | // Hasher is an interface to compute a hash value. 7 | type Hasher interface { 8 | // Hash takes a string and computes its hash value. 9 | // Values must be computed deterministically. 10 | Hash([]byte) uint64 11 | } 12 | -------------------------------------------------------------------------------- /codec/registry.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package codec 5 | 6 | import "errors" 7 | 8 | var ErrDuplicateType = errors.New("duplicate type registration") 9 | 10 | // Registry registers new types that can be marshaled into 11 | type Registry interface { 12 | RegisterType(interface{}) error 13 | } 14 | -------------------------------------------------------------------------------- /vms/nftfx/factory_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package nftfx 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/stretchr/testify/require" 10 | ) 11 | 12 | func TestFactory(t *testing.T) { 13 | require := require.New(t) 14 | 15 | factory := Factory{} 16 | require.Equal(&Fx{}, factory.New()) 17 | } 18 | -------------------------------------------------------------------------------- /vms/secp256k1fx/factory_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package secp256k1fx 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/stretchr/testify/require" 10 | ) 11 | 12 | func TestFactory(t *testing.T) { 13 | require := require.New(t) 14 | factory := Factory{} 15 | require.Equal(&Fx{}, factory.New()) 16 | } 17 | -------------------------------------------------------------------------------- /tests/load/contracts/TrieStressTest.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | contract TrieStressTest { 5 | bytes32[] private data; 6 | 7 | function writeValues(uint value) public { 8 | bytes32 dataToPush = bytes32(uint256(uint160(msg.sender)) << 96); 9 | for (uint i = 0; i < value; i++) { 10 | data.push(dataToPush); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /utils/constants/application.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package constants 5 | 6 | // Const variables to be exported 7 | const ( 8 | // PlatformName exports the name of the platform 9 | PlatformName = "avalanche" 10 | 11 | // AppName exports the name of the avalanche application 12 | AppName = "avalanchego" 13 | ) 14 | -------------------------------------------------------------------------------- /utils/timer/meter.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package timer 5 | 6 | // Meter tracks the number of occurrences of a specified event 7 | type Meter interface { 8 | // Notify this meter of a new event for it to rate 9 | Tick() 10 | // Return the number of events this meter is currently tracking 11 | Ticks() int 12 | } 13 | -------------------------------------------------------------------------------- /vms/propertyfx/factory_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package propertyfx 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/stretchr/testify/require" 10 | ) 11 | 12 | func TestFactory(t *testing.T) { 13 | require := require.New(t) 14 | 15 | factory := Factory{} 16 | require.Equal(&Fx{}, factory.New()) 17 | } 18 | -------------------------------------------------------------------------------- /utils/formatting/int_format.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package formatting 5 | 6 | import ( 7 | "fmt" 8 | "math" 9 | ) 10 | 11 | func IntFormat(maxValue int) string { 12 | log := 1 13 | if maxValue > 0 { 14 | log = int(math.Ceil(math.Log10(float64(maxValue + 1)))) 15 | } 16 | return fmt.Sprintf("%%0%dd", log) 17 | } 18 | -------------------------------------------------------------------------------- /vms/platformvm/warp/message/README.md: -------------------------------------------------------------------------------- 1 | ## P-Chain warp message payloads 2 | 3 | This package defines parsing and serialization for the payloads of unsigned warp messages on the P-Chain. 4 | 5 | These payloads are specified in [ACP-77](https://github.com/avalanche-foundation/ACPs/blob/main/ACPs/77-reinventing-subnets/README.md), and are expected as part of the `payload` field of an `AddressedCall` message, with an empty source address. -------------------------------------------------------------------------------- /proto/warp/message.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package warp; 4 | 5 | option go_package = "github.com/ava-labs/avalanchego/proto/pb/warp"; 6 | 7 | service Signer { 8 | rpc Sign(SignRequest) returns (SignResponse); 9 | } 10 | 11 | message SignRequest { 12 | uint32 network_id = 1; 13 | bytes source_chain_id = 2; 14 | bytes payload = 3; 15 | } 16 | 17 | message SignResponse { 18 | bytes signature = 1; 19 | } 20 | -------------------------------------------------------------------------------- /scripts/build_antithesis_xsvm_workload.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | 5 | # Directory above this script 6 | AVALANCHE_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd ) 7 | # Load the constants 8 | source "$AVALANCHE_PATH"/scripts/constants.sh 9 | 10 | echo "Building Workload..." 11 | go build -o "$AVALANCHE_PATH/build/antithesis-xsvm-workload" "$AVALANCHE_PATH/tests/antithesis/xsvm/"*.go 12 | -------------------------------------------------------------------------------- /snow/consensus/snowman/topological_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package snowman 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/ava-labs/avalanchego/snow/consensus/snowball" 10 | ) 11 | 12 | func TestTopological(t *testing.T) { 13 | runConsensusTests(t, TopologicalFactory{factory: snowball.SnowflakeFactory}) 14 | } 15 | -------------------------------------------------------------------------------- /tests/fixture/tmpnet/detached_process_default.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | //go:build linux || darwin || unix 5 | 6 | package tmpnet 7 | 8 | import ( 9 | "os/exec" 10 | "syscall" 11 | ) 12 | 13 | func configureDetachedProcess(cmd *exec.Cmd) { 14 | cmd.SysProcAttr = &syscall.SysProcAttr{ 15 | Setsid: true, 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/fixture/tmpnet/flags/common.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package flags 5 | 6 | // The following function signature is common across flag and 7 | // spf13/pflag. It can be used to define a single registration method 8 | // that supports both flag libraries. 9 | type varFunc[T any] func(p *T, name string, value T, usage string) 10 | -------------------------------------------------------------------------------- /vms/components/avax/state.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package avax 5 | 6 | const ( 7 | codecVersion = 0 8 | ) 9 | 10 | // Addressable is the interface a feature extension must provide to be able to 11 | // be tracked as a part of the utxo set for a set of addresses 12 | type Addressable interface { 13 | Addresses() [][]byte 14 | } 15 | -------------------------------------------------------------------------------- /vms/platformvm/block/parse.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package block 5 | 6 | import "github.com/ava-labs/avalanchego/codec" 7 | 8 | func Parse(c codec.Manager, b []byte) (Block, error) { 9 | var blk Block 10 | if _, err := c.Unmarshal(b, &blk); err != nil { 11 | return nil, err 12 | } 13 | return blk, blk.initialize(b) 14 | } 15 | -------------------------------------------------------------------------------- /utils/compression/compressor.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package compression 5 | 6 | // Compressor compress and decompresses messages. 7 | // Decompress is the inverse of Compress. 8 | // Decompress(Compress(msg)) == msg. 9 | type Compressor interface { 10 | Compress([]byte) ([]byte, error) 11 | Decompress([]byte) ([]byte, error) 12 | } 13 | -------------------------------------------------------------------------------- /version/version_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package version 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/stretchr/testify/require" 10 | ) 11 | 12 | func TestSemanticString(t *testing.T) { 13 | v := Semantic{ 14 | Major: 1, 15 | Minor: 2, 16 | Patch: 3, 17 | } 18 | 19 | require.Equal(t, "v1.2.3", v.String()) 20 | } 21 | -------------------------------------------------------------------------------- /vms/avm/state/versions.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package state 5 | 6 | import "github.com/ava-labs/avalanchego/ids" 7 | 8 | type Versions interface { 9 | // GetState returns the state of the chain after [blkID] has been accepted. 10 | // If the state is not known, `false` will be returned. 11 | GetState(blkID ids.ID) (Chain, bool) 12 | } 13 | -------------------------------------------------------------------------------- /vms/platformvm/signer/empty.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package signer 5 | 6 | import "github.com/ava-labs/avalanchego/utils/crypto/bls" 7 | 8 | var _ Signer = (*Empty)(nil) 9 | 10 | type Empty struct{} 11 | 12 | func (*Empty) Verify() error { 13 | return nil 14 | } 15 | 16 | func (*Empty) Key() *bls.PublicKey { 17 | return nil 18 | } 19 | -------------------------------------------------------------------------------- /vms/platformvm/signer/empty_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package signer 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/stretchr/testify/require" 10 | ) 11 | 12 | func TestEmpty(t *testing.T) { 13 | require := require.New(t) 14 | noSigner := &Empty{} 15 | require.NoError(noSigner.Verify()) 16 | require.Nil(noSigner.Key()) 17 | } 18 | -------------------------------------------------------------------------------- /scripts/build_antithesis_avalanchego_workload.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | 5 | # Directory above this script 6 | AVALANCHE_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd ) 7 | # Load the constants 8 | source "$AVALANCHE_PATH"/scripts/constants.sh 9 | 10 | echo "Building Workload..." 11 | go build -o "$AVALANCHE_PATH/build/antithesis-avalanchego-workload" "$AVALANCHE_PATH/tests/antithesis/avalanchego/"*.go 12 | -------------------------------------------------------------------------------- /trace/noop.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package trace 5 | 6 | import "go.opentelemetry.io/otel/trace/noop" 7 | 8 | var Noop Tracer = noOpTracer{} 9 | 10 | // noOpTracer is an implementation of trace.Tracer that does nothing. 11 | type noOpTracer struct { 12 | noop.Tracer 13 | } 14 | 15 | func (noOpTracer) Close() error { 16 | return nil 17 | } 18 | -------------------------------------------------------------------------------- /subnets/no_op_allower.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package subnets 5 | 6 | import "github.com/ava-labs/avalanchego/ids" 7 | 8 | // NoOpAllower is an Allower that always returns true 9 | var NoOpAllower Allower = noOpAllower{} 10 | 11 | type noOpAllower struct{} 12 | 13 | func (noOpAllower) IsAllowed(ids.NodeID, bool) bool { 14 | return true 15 | } 16 | -------------------------------------------------------------------------------- /utils/timer/timer_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package timer 5 | 6 | import ( 7 | "sync" 8 | "testing" 9 | "time" 10 | ) 11 | 12 | func TestTimer(*testing.T) { 13 | wg := sync.WaitGroup{} 14 | wg.Add(1) 15 | defer wg.Wait() 16 | 17 | timer := NewTimer(wg.Done) 18 | go timer.Dispatch() 19 | 20 | timer.SetTimeoutIn(time.Millisecond) 21 | } 22 | -------------------------------------------------------------------------------- /vms/platformvm/state/versions.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package state 5 | 6 | import "github.com/ava-labs/avalanchego/ids" 7 | 8 | type Versions interface { 9 | // GetState returns the state of the chain after [blkID] has been accepted. 10 | // If the state is not known, `false` will be returned. 11 | GetState(blkID ids.ID) (Chain, bool) 12 | } 13 | -------------------------------------------------------------------------------- /version/constants_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package version 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/stretchr/testify/require" 10 | ) 11 | 12 | func TestCurrentRPCChainVMCompatible(t *testing.T) { 13 | compatibleVersions := RPCChainVMProtocolCompatibility[RPCChainVMProtocol] 14 | require.Contains(t, compatibleVersions, Current) 15 | } 16 | -------------------------------------------------------------------------------- /vms/example/xsvm/factory.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package xsvm 5 | 6 | import ( 7 | "github.com/ava-labs/avalanchego/utils/logging" 8 | "github.com/ava-labs/avalanchego/vms" 9 | ) 10 | 11 | var _ vms.Factory = (*Factory)(nil) 12 | 13 | type Factory struct{} 14 | 15 | func (*Factory) New(logging.Logger) (interface{}, error) { 16 | return &VM{}, nil 17 | } 18 | -------------------------------------------------------------------------------- /vms/proposervm/block/header_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package block 5 | 6 | import "github.com/stretchr/testify/require" 7 | 8 | func equalHeader(require *require.Assertions, want, have Header) { 9 | require.Equal(want.ChainID(), have.ChainID()) 10 | require.Equal(want.ParentID(), have.ParentID()) 11 | require.Equal(want.BodyID(), have.BodyID()) 12 | } 13 | -------------------------------------------------------------------------------- /snow/consensus/snowman/bootstrapper/poll_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package bootstrapper 5 | 6 | import "github.com/ava-labs/avalanchego/ids" 7 | 8 | var ( 9 | nodeID0 = ids.GenerateTestNodeID() 10 | nodeID1 = ids.GenerateTestNodeID() 11 | nodeID2 = ids.GenerateTestNodeID() 12 | 13 | blkID0 = ids.GenerateTestID() 14 | blkID1 = ids.GenerateTestID() 15 | ) 16 | -------------------------------------------------------------------------------- /vms/mocks_generate_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package vms 5 | 6 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE}mock -destination=${GOPACKAGE}mock/factory.go -mock_names=Factory=Factory . Factory 7 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE}mock -destination=${GOPACKAGE}mock/manager.go -mock_names=Manager=Manager . Manager 8 | -------------------------------------------------------------------------------- /database/mocks_generate_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package database 5 | 6 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE}mock -destination=${GOPACKAGE}mock/batch.go -mock_names=Batch=Batch . Batch 7 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE}mock -destination=${GOPACKAGE}mock/iterator.go -mock_names=Iterator=Iterator . Iterator 8 | -------------------------------------------------------------------------------- /snow/engine/common/request.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package common 5 | 6 | import ( 7 | "fmt" 8 | 9 | "github.com/ava-labs/avalanchego/ids" 10 | ) 11 | 12 | type Request struct { 13 | NodeID ids.NodeID 14 | RequestID uint32 15 | } 16 | 17 | func (r Request) MarshalText() ([]byte, error) { 18 | return fmt.Appendf(nil, "%s:%d", r.NodeID, r.RequestID), nil 19 | } 20 | -------------------------------------------------------------------------------- /utils/dynamicip/no_updater.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package dynamicip 5 | 6 | import "github.com/ava-labs/avalanchego/utils/logging" 7 | 8 | var _ Updater = noUpdater{} 9 | 10 | func NewNoUpdater() Updater { 11 | return noUpdater{} 12 | } 13 | 14 | type noUpdater struct{} 15 | 16 | func (noUpdater) Dispatch(logging.Logger) {} 17 | 18 | func (noUpdater) Stop() {} 19 | -------------------------------------------------------------------------------- /utils/hashing/consistent/hashable.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package consistent 5 | 6 | // Hashable is an interface to be implemented by structs that need to be sharded via consistent hashing. 7 | type Hashable interface { 8 | // ConsistentHashKey is the key used to shard the blob. 9 | // This should be constant for a given blob. 10 | ConsistentHashKey() []byte 11 | } 12 | -------------------------------------------------------------------------------- /utils/sampler/weighted.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package sampler 5 | 6 | // Weighted defines how to sample a specified valued based on a provided 7 | // weighted distribution 8 | type Weighted interface { 9 | Initialize(weights []uint64) error 10 | Sample(sampleValue uint64) (int, bool) 11 | } 12 | 13 | func NewWeighted() Weighted { 14 | return &weightedHeap{} 15 | } 16 | -------------------------------------------------------------------------------- /x/archivedb/value.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package archivedb 5 | 6 | func newDBValue(value []byte) []byte { 7 | dbValue := make([]byte, len(value)+1) 8 | copy(dbValue[1:], value) 9 | return dbValue 10 | } 11 | 12 | func parseDBValue(dbValue []byte) ([]byte, bool) { 13 | if len(dbValue) == 0 { 14 | return nil, false 15 | } 16 | return dbValue[1:], true 17 | } 18 | -------------------------------------------------------------------------------- /vms/nftfx/credential_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package nftfx 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/stretchr/testify/require" 10 | 11 | "github.com/ava-labs/avalanchego/vms/components/verify" 12 | ) 13 | 14 | func TestCredentialState(t *testing.T) { 15 | intf := interface{}(&Credential{}) 16 | _, ok := intf.(verify.State) 17 | require.False(t, ok) 18 | } 19 | -------------------------------------------------------------------------------- /vms/nftfx/mint_output_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package nftfx 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/stretchr/testify/require" 10 | 11 | "github.com/ava-labs/avalanchego/vms/components/verify" 12 | ) 13 | 14 | func TestMintOutputState(t *testing.T) { 15 | intf := interface{}(&MintOutput{}) 16 | _, ok := intf.(verify.State) 17 | require.True(t, ok) 18 | } 19 | -------------------------------------------------------------------------------- /utils/crypto/bls/blstest/benchmark.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package blstest 5 | 6 | var ( 7 | BenchmarkSizes = []int{ 8 | 1, 9 | 2, 10 | 4, 11 | 8, 12 | 16, 13 | 32, 14 | 64, 15 | 128, 16 | 256, 17 | 512, 18 | 1024, 19 | 2048, 20 | 4096, 21 | 8192, 22 | 16384, 23 | 32768, 24 | } 25 | BiggestBenchmarkSize = BenchmarkSizes[len(BenchmarkSizes)-1] 26 | ) 27 | -------------------------------------------------------------------------------- /snow/networking/tracker/mocks_generate_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package tracker 5 | 6 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE}mock -destination=${GOPACKAGE}mock/targeter.go -mock_names=Targeter=Targeter . Targeter 7 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE}mock -destination=${GOPACKAGE}mock/tracker.go -mock_names=Tracker=Tracker . Tracker 8 | -------------------------------------------------------------------------------- /utils/units/avax.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package units 5 | 6 | // Denominations of value 7 | const ( 8 | NanoAvax uint64 = 1 9 | MicroAvax uint64 = 1000 * NanoAvax 10 | Schmeckle uint64 = 49*MicroAvax + 463*NanoAvax 11 | MilliAvax uint64 = 1000 * MicroAvax 12 | Avax uint64 = 1000 * MilliAvax 13 | KiloAvax uint64 = 1000 * Avax 14 | MegaAvax uint64 = 1000 * KiloAvax 15 | ) 16 | -------------------------------------------------------------------------------- /utils/wrappers/errors.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package wrappers 5 | 6 | type Errs struct{ Err error } 7 | 8 | func (errs *Errs) Errored() bool { 9 | return errs.Err != nil 10 | } 11 | 12 | func (errs *Errs) Add(errors ...error) { 13 | if errs.Err == nil { 14 | for _, err := range errors { 15 | if err != nil { 16 | errs.Err = err 17 | break 18 | } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /vms/platformvm/state/mocks_generate_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package state 5 | 6 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE} -destination=mock_diff.go . Diff 7 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE} -destination=mock_state.go . State 8 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE} -destination=mock_chain.go . Chain 9 | -------------------------------------------------------------------------------- /vms/propertyfx/credential_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package propertyfx 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/stretchr/testify/require" 10 | 11 | "github.com/ava-labs/avalanchego/vms/components/verify" 12 | ) 13 | 14 | func TestCredentialState(t *testing.T) { 15 | intf := interface{}(&Credential{}) 16 | _, ok := intf.(verify.State) 17 | require.False(t, ok) 18 | } 19 | -------------------------------------------------------------------------------- /vms/propertyfx/mint_output.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package propertyfx 5 | 6 | import ( 7 | "github.com/ava-labs/avalanchego/vms/components/verify" 8 | "github.com/ava-labs/avalanchego/vms/secp256k1fx" 9 | ) 10 | 11 | var _ verify.State = (*MintOutput)(nil) 12 | 13 | type MintOutput struct { 14 | verify.IsState `json:"-"` 15 | 16 | secp256k1fx.OutputOwners `serialize:"true"` 17 | } 18 | -------------------------------------------------------------------------------- /vms/propertyfx/mint_output_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package propertyfx 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/stretchr/testify/require" 10 | 11 | "github.com/ava-labs/avalanchego/vms/components/verify" 12 | ) 13 | 14 | func TestMintOutputState(t *testing.T) { 15 | intf := interface{}(&MintOutput{}) 16 | _, ok := intf.(verify.State) 17 | require.True(t, ok) 18 | } 19 | -------------------------------------------------------------------------------- /tests/e2e/ignore.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package e2e 5 | 6 | // This file is required by ginkgo to accurately report compilation errors in test packages. Without 7 | // it, the following error will mask the actual errors: 8 | // 9 | // ``` 10 | // Failed to compile e2e: 11 | // 12 | // github.com/ava-labs/avalanchego/tests/e2e: no non-test Go files in /path/to/avalanchego/tests/e2e 13 | // ``` 14 | -------------------------------------------------------------------------------- /vms/propertyfx/owned_output.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package propertyfx 5 | 6 | import ( 7 | "github.com/ava-labs/avalanchego/vms/components/verify" 8 | "github.com/ava-labs/avalanchego/vms/secp256k1fx" 9 | ) 10 | 11 | var _ verify.State = (*OwnedOutput)(nil) 12 | 13 | type OwnedOutput struct { 14 | verify.IsState `json:"-"` 15 | 16 | secp256k1fx.OutputOwners `serialize:"true"` 17 | } 18 | -------------------------------------------------------------------------------- /vms/propertyfx/owned_output_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package propertyfx 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/stretchr/testify/require" 10 | 11 | "github.com/ava-labs/avalanchego/vms/components/verify" 12 | ) 13 | 14 | func TestOwnedOutputState(t *testing.T) { 15 | intf := interface{}(&OwnedOutput{}) 16 | _, ok := intf.(verify.State) 17 | require.True(t, ok) 18 | } 19 | -------------------------------------------------------------------------------- /vms/registry/mocks_generate_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package registry 5 | 6 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE}mock -destination=${GOPACKAGE}mock/vm_getter.go -mock_names=VMGetter=VMGetter . VMGetter 7 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE}mock -destination=${GOPACKAGE}mock/vm_registry.go -mock_names=VMRegistry=VMRegistry . VMRegistry 8 | -------------------------------------------------------------------------------- /.github/workflows/fuzz.yml: -------------------------------------------------------------------------------- 1 | name: Run fuzz tests 2 | 3 | on: 4 | schedule: 5 | - cron: "0 0 * * *" # Once a day at midnight UTC 6 | 7 | permissions: 8 | contents: read 9 | 10 | jobs: 11 | fuzz: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - name: Git checkout 15 | uses: actions/checkout@v4 16 | - name: Set up Go 17 | uses: ./.github/actions/setup-go-for-project 18 | - name: Run fuzz tests 19 | run: ./scripts/run_task.sh test-fuzz-long 20 | -------------------------------------------------------------------------------- /utils/math/averager.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package math 5 | 6 | import "time" 7 | 8 | // Averager tracks a continuous time exponential moving average of the provided 9 | // values. 10 | type Averager interface { 11 | // Observe the value at the given time 12 | Observe(value float64, currentTime time.Time) 13 | 14 | // Read returns the average of the provided values. 15 | Read() float64 16 | } 17 | -------------------------------------------------------------------------------- /network/conn_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package network 5 | 6 | import "net" 7 | 8 | var _ net.Conn = (*testConn)(nil) 9 | 10 | type testConn struct { 11 | net.Conn 12 | 13 | localAddr net.Addr 14 | remoteAddr net.Addr 15 | } 16 | 17 | func (c *testConn) LocalAddr() net.Addr { 18 | return c.localAddr 19 | } 20 | 21 | func (c *testConn) RemoteAddr() net.Addr { 22 | return c.remoteAddr 23 | } 24 | -------------------------------------------------------------------------------- /snow/consensus/snowman/snowmantest/require.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package snowmantest 5 | 6 | import ( 7 | "github.com/stretchr/testify/require" 8 | 9 | "github.com/ava-labs/avalanchego/snow/snowtest" 10 | ) 11 | 12 | func RequireStatusIs(require *require.Assertions, status snowtest.Status, blks ...*Block) { 13 | for i, blk := range blks { 14 | require.Equal(status, blk.Status, i) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /proto/aliasreader/aliasreader.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package aliasreader; 4 | 5 | option go_package = "github.com/ava-labs/avalanchego/proto/pb/aliasreader"; 6 | 7 | service AliasReader { 8 | rpc Lookup(Alias) returns (ID); 9 | rpc PrimaryAlias(ID) returns (Alias); 10 | rpc Aliases(ID) returns (AliasList); 11 | } 12 | 13 | message ID { 14 | bytes id = 1; 15 | } 16 | 17 | message Alias { 18 | string alias = 1; 19 | } 20 | 21 | message AliasList { 22 | repeated string aliases = 1; 23 | } 24 | -------------------------------------------------------------------------------- /ids/request_id.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package ids 5 | 6 | // RequestID is a unique identifier for an in-flight request pending a response. 7 | type RequestID struct { 8 | // The node this request came from 9 | NodeID NodeID 10 | // The chain the expected response should come from 11 | ChainID ID 12 | // The unique identifier for this request 13 | RequestID uint32 14 | // The message opcode 15 | Op byte 16 | } 17 | -------------------------------------------------------------------------------- /network/p2p/node_sampler.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package p2p 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/ava-labs/avalanchego/ids" 10 | ) 11 | 12 | // NodeSampler samples nodes in network 13 | type NodeSampler interface { 14 | // Sample returns at most [limit] nodes. This may return fewer nodes if 15 | // fewer than [limit] are available. 16 | Sample(ctx context.Context, limit int) []ids.NodeID 17 | } 18 | -------------------------------------------------------------------------------- /utils/password/hash_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package password 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/stretchr/testify/require" 10 | ) 11 | 12 | func TestHash(t *testing.T) { 13 | require := require.New(t) 14 | 15 | h := Hash{} 16 | require.NoError(h.Set("heytherepal")) 17 | require.True(h.Check("heytherepal")) 18 | require.False(h.Check("heytherepal!")) 19 | require.False(h.Check("")) 20 | } 21 | -------------------------------------------------------------------------------- /utils/iterator/empty.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package iterator 5 | 6 | import "github.com/ava-labs/avalanchego/utils" 7 | 8 | var _ Iterator[any] = Empty[any]{} 9 | 10 | // Empty is an iterator with no elements. 11 | type Empty[T any] struct{} 12 | 13 | func (Empty[_]) Next() bool { 14 | return false 15 | } 16 | 17 | func (Empty[T]) Value() T { 18 | return utils.Zero[T]() 19 | } 20 | 21 | func (Empty[_]) Release() {} 22 | -------------------------------------------------------------------------------- /utils/iterator/empty_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package iterator 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/stretchr/testify/require" 10 | ) 11 | 12 | func TestEmpty(t *testing.T) { 13 | var ( 14 | require = require.New(t) 15 | empty = Empty[*int]{} 16 | ) 17 | 18 | require.False(empty.Next()) 19 | 20 | empty.Release() 21 | 22 | require.False(empty.Next()) 23 | require.Nil(empty.Value()) 24 | } 25 | -------------------------------------------------------------------------------- /vms/evm/metrics/prometheus/interfaces.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package prometheus 5 | 6 | import "github.com/ava-labs/libevm/metrics" 7 | 8 | var _ Registry = metrics.Registry(nil) 9 | 10 | type Registry interface { 11 | // Call the given function for each registered metric. 12 | Each(func(name string, metric any)) 13 | // Get the metric by the given name or nil if none is registered. 14 | Get(name string) any 15 | } 16 | -------------------------------------------------------------------------------- /config/node/process_context.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package node 5 | 6 | import "net/netip" 7 | 8 | type ProcessContext struct { 9 | // The process id of the node 10 | PID int `json:"pid"` 11 | // URI to access the node API 12 | // Format: [https|http]://[host]:[port] 13 | URI string `json:"uri"` 14 | // Address other nodes can use to communicate with this node 15 | StakingAddress netip.AddrPort `json:"stakingAddress"` 16 | } 17 | -------------------------------------------------------------------------------- /utils/storage/storage_openbsd.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | //go:build openbsd 5 | // +build openbsd 6 | 7 | package storage 8 | 9 | import "syscall" 10 | 11 | func AvailableBytes(storagePath string) (uint64, error) { 12 | var stat syscall.Statfs_t 13 | err := syscall.Statfs(storagePath, &stat) 14 | if err != nil { 15 | return 0, err 16 | } 17 | avail := uint64(stat.F_bavail) * uint64(stat.F_bsize) 18 | return avail, nil 19 | } 20 | -------------------------------------------------------------------------------- /vms/secp256k1fx/tx.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package secp256k1fx 5 | 6 | // UnsignedTx that this Fx is supporting 7 | type UnsignedTx interface { 8 | Bytes() []byte 9 | } 10 | 11 | var _ UnsignedTx = (*TestTx)(nil) 12 | 13 | // TestTx is a minimal implementation of a Tx 14 | type TestTx struct{ UnsignedBytes []byte } 15 | 16 | // Bytes returns UnsignedBytes 17 | func (tx *TestTx) Bytes() []byte { 18 | return tx.UnsignedBytes 19 | } 20 | -------------------------------------------------------------------------------- /.github/workflows/build-tgz-pkg.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | 5 | AVALANCHE_ROOT=$PKG_ROOT/avalanchego-$TAG 6 | 7 | mkdir -p "$AVALANCHE_ROOT" 8 | 9 | OK=$(cp ./build/avalanchego "$AVALANCHE_ROOT") 10 | if [[ $OK -ne 0 ]]; then 11 | exit "$OK"; 12 | fi 13 | 14 | 15 | echo "Build tgz package..." 16 | cd "$PKG_ROOT" 17 | echo "Tag: $TAG" 18 | tar -czvf "avalanchego-linux-$ARCH-$TAG.tar.gz" "avalanchego-$TAG" 19 | aws s3 cp "avalanchego-linux-$ARCH-$TAG.tar.gz" "s3://$BUCKET/linux/binaries/ubuntu/$RELEASE/$ARCH/" 20 | -------------------------------------------------------------------------------- /scripts/image_tag.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | 5 | # Defines an image tag derived from the current branch or tag 6 | 7 | image_tag="$( git symbolic-ref -q --short HEAD || git describe --tags --exact-match || true )" 8 | if [[ -z "${image_tag}" ]]; then 9 | # Supply a default tag when one is not discovered 10 | image_tag=ci_dummy 11 | elif [[ "${image_tag}" == */* ]]; then 12 | # Slashes are not legal for docker image tags - replace with dashes 13 | image_tag="$( echo "${image_tag}" | tr '/' '-' )" 14 | fi 15 | -------------------------------------------------------------------------------- /scripts/tests.e2e.bootstrap_monitor.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | 5 | # Run e2e tests for bootstrap monitor. 6 | # 7 | # --kubeconfig and --kubeconfig-context should be provided in the form --arg=value 8 | # to work with the simplistic mechanism enabling flag reuse. 9 | 10 | if ! [[ "$0" =~ scripts/tests.e2e.bootstrap_monitor.sh ]]; then 11 | echo "must be run from repository root" 12 | exit 255 13 | fi 14 | 15 | ./scripts/start_kind_cluster.sh "$@" 16 | ./bin/ginkgo -v ./tests/fixture/bootstrapmonitor/e2e "$@" 17 | -------------------------------------------------------------------------------- /utils/compression/no_compressor.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package compression 5 | 6 | var _ Compressor = (*noCompressor)(nil) 7 | 8 | type noCompressor struct{} 9 | 10 | func (*noCompressor) Compress(msg []byte) ([]byte, error) { 11 | return msg, nil 12 | } 13 | 14 | func (*noCompressor) Decompress(msg []byte) ([]byte, error) { 15 | return msg, nil 16 | } 17 | 18 | func NewNoCompressor() Compressor { 19 | return &noCompressor{} 20 | } 21 | -------------------------------------------------------------------------------- /utils/storage/storage_unix.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | //go:build !windows && !openbsd 5 | // +build !windows,!openbsd 6 | 7 | package storage 8 | 9 | import "syscall" 10 | 11 | func AvailableBytes(storagePath string) (uint64, error) { 12 | var stat syscall.Statfs_t 13 | err := syscall.Statfs(storagePath, &stat) 14 | if err != nil { 15 | return 0, err 16 | } 17 | avail := stat.Bavail * uint64(stat.Bsize) 18 | return avail, nil 19 | } 20 | -------------------------------------------------------------------------------- /x/merkledb/tracer.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package merkledb 5 | 6 | import "github.com/ava-labs/avalanchego/trace" 7 | 8 | const ( 9 | DebugTrace TraceLevel = iota - 1 10 | InfoTrace // Default 11 | NoTrace 12 | ) 13 | 14 | type TraceLevel int 15 | 16 | func getTracerIfEnabled(level, minLevel TraceLevel, tracer trace.Tracer) trace.Tracer { 17 | if level <= minLevel { 18 | return tracer 19 | } 20 | return trace.Noop 21 | } 22 | -------------------------------------------------------------------------------- /snow/engine/common/halter.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package common 5 | 6 | import "sync/atomic" 7 | 8 | var _ Haltable = (*Halter)(nil) 9 | 10 | type Haltable interface { 11 | Halt() 12 | Halted() bool 13 | } 14 | 15 | type Halter struct { 16 | halted uint32 17 | } 18 | 19 | func (h *Halter) Halt() { 20 | atomic.StoreUint32(&h.halted, 1) 21 | } 22 | 23 | func (h *Halter) Halted() bool { 24 | return atomic.LoadUint32(&h.halted) == 1 25 | } 26 | -------------------------------------------------------------------------------- /vms/avm/config/config.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package config 5 | 6 | import "github.com/ava-labs/avalanchego/upgrade" 7 | 8 | // Struct collecting all the foundational parameters of the AVM 9 | type Config struct { 10 | Upgrades upgrade.Config 11 | 12 | // Fee that is burned by every non-asset creating transaction 13 | TxFee uint64 14 | 15 | // Fee that must be burned by every asset creating transaction 16 | CreateAssetTxFee uint64 17 | } 18 | -------------------------------------------------------------------------------- /vms/avm/factory.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package avm 5 | 6 | import ( 7 | "github.com/ava-labs/avalanchego/utils/logging" 8 | "github.com/ava-labs/avalanchego/vms" 9 | "github.com/ava-labs/avalanchego/vms/avm/config" 10 | ) 11 | 12 | var _ vms.Factory = (*Factory)(nil) 13 | 14 | type Factory struct { 15 | config.Config 16 | } 17 | 18 | func (f *Factory) New(logging.Logger) (interface{}, error) { 19 | return &VM{Config: f.Config}, nil 20 | } 21 | -------------------------------------------------------------------------------- /vms/nftfx/factory.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package nftfx 5 | 6 | import ( 7 | "github.com/ava-labs/avalanchego/ids" 8 | "github.com/ava-labs/avalanchego/vms/fx" 9 | ) 10 | 11 | const Name = "nftfx" 12 | 13 | var ( 14 | _ fx.Factory = (*Factory)(nil) 15 | 16 | // ID that this Fx uses when labeled 17 | ID = ids.ID{'n', 'f', 't', 'f', 'x'} 18 | ) 19 | 20 | type Factory struct{} 21 | 22 | func (*Factory) New() any { 23 | return &Fx{} 24 | } 25 | -------------------------------------------------------------------------------- /x/merkledb/batch.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package merkledb 5 | 6 | import "github.com/ava-labs/avalanchego/database" 7 | 8 | var _ database.Batch = (*batch)(nil) 9 | 10 | type batch struct { 11 | database.BatchOps 12 | 13 | db *merkleDB 14 | } 15 | 16 | // Assumes [b.db.lock] isn't held. 17 | func (b *batch) Write() error { 18 | return b.db.commitBatch(b.Ops) 19 | } 20 | 21 | func (b *batch) Inner() database.Batch { 22 | return b 23 | } 24 | -------------------------------------------------------------------------------- /message/mocks_generate_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package message 5 | 6 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE}mock -destination=${GOPACKAGE}mock/outbound_message.go -mock_names=OutboundMessage=OutboundMessage . OutboundMessage 7 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE}mock -destination=${GOPACKAGE}mock/outbound_message_builder.go -mock_names=OutboundMsgBuilder=OutboundMsgBuilder . OutboundMsgBuilder 8 | -------------------------------------------------------------------------------- /vms/proposervm/proposer/validators.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package proposer 5 | 6 | import ( 7 | "github.com/ava-labs/avalanchego/ids" 8 | "github.com/ava-labs/avalanchego/utils" 9 | ) 10 | 11 | var _ utils.Sortable[validatorData] = validatorData{} 12 | 13 | type validatorData struct { 14 | id ids.NodeID 15 | weight uint64 16 | } 17 | 18 | func (d validatorData) Compare(other validatorData) int { 19 | return d.id.Compare(other.id) 20 | } 21 | -------------------------------------------------------------------------------- /utils/resource/no_usage.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package resource 5 | 6 | import "math" 7 | 8 | // NoUsage implements Usage() by always returning 0. 9 | var NoUsage User = noUsage{} 10 | 11 | type noUsage struct{} 12 | 13 | func (noUsage) CPUUsage() float64 { 14 | return 0 15 | } 16 | 17 | func (noUsage) DiskUsage() (float64, float64) { 18 | return 0, 0 19 | } 20 | 21 | func (noUsage) AvailableDiskBytes() uint64 { 22 | return math.MaxUint64 23 | } 24 | -------------------------------------------------------------------------------- /.github/workflows/fuzz_merkledb.yml: -------------------------------------------------------------------------------- 1 | name: Scheduled Fuzz Testing 2 | 3 | on: 4 | workflow_dispatch: 5 | schedule: 6 | # Run every 6 hours 7 | - cron: "0 0,6,12,18 * * *" 8 | 9 | permissions: 10 | contents: read 11 | 12 | jobs: 13 | MerkleDB: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - name: Git checkout 17 | uses: actions/checkout@v4 18 | - name: Set up Go 19 | uses: ./.github/actions/setup-go-for-project 20 | - name: Run merkledb fuzz tests 21 | run: ./scripts/run_task.sh test-fuzz-merkledb 22 | -------------------------------------------------------------------------------- /snow/networking/handler/parser.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package handler 5 | 6 | import ( 7 | "github.com/ava-labs/avalanchego/ids" 8 | "github.com/ava-labs/avalanchego/utils/set" 9 | ) 10 | 11 | func getIDs(idsBytes [][]byte) (set.Set[ids.ID], error) { 12 | var res set.Set[ids.ID] 13 | for _, bytes := range idsBytes { 14 | id, err := ids.ToID(bytes) 15 | if err != nil { 16 | return nil, err 17 | } 18 | res.Add(id) 19 | } 20 | return res, nil 21 | } 22 | -------------------------------------------------------------------------------- /vms/secp256k1fx/mint_output.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package secp256k1fx 5 | 6 | import "github.com/ava-labs/avalanchego/vms/components/verify" 7 | 8 | var _ verify.State = (*MintOutput)(nil) 9 | 10 | type MintOutput struct { 11 | verify.IsState `json:"-"` 12 | 13 | OutputOwners `serialize:"true"` 14 | } 15 | 16 | func (out *MintOutput) Verify() error { 17 | if out == nil { 18 | return ErrNilOutput 19 | } 20 | 21 | return out.OutputOwners.Verify() 22 | } 23 | -------------------------------------------------------------------------------- /scripts/build_tmpnetctl.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | 5 | # Avalanchego root folder 6 | AVALANCHE_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd ) 7 | # Load the constants 8 | source "$AVALANCHE_PATH"/scripts/constants.sh 9 | source "$AVALANCHE_PATH"/scripts/git_commit.sh 10 | 11 | echo "Building tmpnetctl..." 12 | go build -ldflags\ 13 | "-X github.com/ava-labs/avalanchego/version.GitCommit=$git_commit $static_ld_flags"\ 14 | -o "$AVALANCHE_PATH/build/tmpnetctl"\ 15 | "$AVALANCHE_PATH/tests/fixture/tmpnet/tmpnetctl/"*.go 16 | -------------------------------------------------------------------------------- /scripts/git_commit.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Ignore warnings about variables appearing unused since this file is not the consumer of the variables it defines. 4 | # shellcheck disable=SC2034 5 | 6 | set -euo pipefail 7 | 8 | AVALANCHE_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd ) # Directory above this script 9 | 10 | # WARNING: this will use the most recent commit even if there are un-committed changes present 11 | git_commit="${AVALANCHEGO_COMMIT:-$(git --git-dir="${AVALANCHE_PATH}/.git" rev-parse HEAD)}" 12 | commit_hash="${git_commit::8}" 13 | -------------------------------------------------------------------------------- /indexer/codec.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package indexer 5 | 6 | import ( 7 | "math" 8 | 9 | "github.com/ava-labs/avalanchego/codec" 10 | "github.com/ava-labs/avalanchego/codec/linearcodec" 11 | ) 12 | 13 | const CodecVersion = 0 14 | 15 | var Codec codec.Manager 16 | 17 | func init() { 18 | lc := linearcodec.NewDefault() 19 | Codec = codec.NewManager(math.MaxInt) 20 | 21 | if err := Codec.RegisterCodec(CodecVersion, lc); err != nil { 22 | panic(err) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /utils/ulimit/ulimit_windows.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | //go:build windows 5 | // +build windows 6 | 7 | package ulimit 8 | 9 | import "github.com/ava-labs/avalanchego/utils/logging" 10 | 11 | const DefaultFDLimit = 16384 12 | 13 | // Set is a no-op for windows and will warn if the default is not used. 14 | func Set(limit uint64, log logging.Logger) error { 15 | if limit != DefaultFDLimit { 16 | log.Warn("fd-limit is not supported for windows") 17 | } 18 | return nil 19 | } 20 | -------------------------------------------------------------------------------- /vms/metervm/metrics.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package metervm 5 | 6 | import ( 7 | "github.com/prometheus/client_golang/prometheus" 8 | 9 | "github.com/ava-labs/avalanchego/utils/metric" 10 | "github.com/ava-labs/avalanchego/utils/wrappers" 11 | ) 12 | 13 | func newAverager(name string, reg prometheus.Registerer, errs *wrappers.Errs) metric.Averager { 14 | return metric.NewAveragerWithErrs( 15 | name, 16 | "time (in ns) of a "+name, 17 | reg, 18 | errs, 19 | ) 20 | } 21 | -------------------------------------------------------------------------------- /vms/platformvm/signer/signer.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package signer 5 | 6 | import ( 7 | "github.com/ava-labs/avalanchego/utils/crypto/bls" 8 | "github.com/ava-labs/avalanchego/vms/components/verify" 9 | ) 10 | 11 | type Signer interface { 12 | verify.Verifiable 13 | 14 | // Key returns the public BLS key if it exists. 15 | // Note: [nil] will be returned if the key does not exist. 16 | // Invariant: Only called after [Verify] returns [nil]. 17 | Key() *bls.PublicKey 18 | } 19 | -------------------------------------------------------------------------------- /vms/propertyfx/burn_operation.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package propertyfx 5 | 6 | import ( 7 | "github.com/ava-labs/avalanchego/snow" 8 | "github.com/ava-labs/avalanchego/vms/components/verify" 9 | "github.com/ava-labs/avalanchego/vms/secp256k1fx" 10 | ) 11 | 12 | type BurnOperation struct { 13 | secp256k1fx.Input `serialize:"true"` 14 | } 15 | 16 | func (*BurnOperation) InitCtx(*snow.Context) {} 17 | 18 | func (*BurnOperation) Outs() []verify.State { 19 | return nil 20 | } 21 | -------------------------------------------------------------------------------- /database/linkeddb/codec.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package linkeddb 5 | 6 | import ( 7 | "math" 8 | 9 | "github.com/ava-labs/avalanchego/codec" 10 | "github.com/ava-labs/avalanchego/codec/linearcodec" 11 | ) 12 | 13 | const CodecVersion = 0 14 | 15 | var Codec codec.Manager 16 | 17 | func init() { 18 | lc := linearcodec.NewDefault() 19 | Codec = codec.NewManager(math.MaxInt32) 20 | 21 | if err := Codec.RegisterCodec(CodecVersion, lc); err != nil { 22 | panic(err) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /utils/metric/namespace.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package metric 5 | 6 | import "strings" 7 | 8 | const ( 9 | NamespaceSeparatorByte = '_' 10 | NamespaceSeparator = string(NamespaceSeparatorByte) 11 | ) 12 | 13 | func AppendNamespace(prefix, suffix string) string { 14 | switch { 15 | case len(prefix) == 0: 16 | return suffix 17 | case len(suffix) == 0: 18 | return prefix 19 | default: 20 | return strings.Join([]string{prefix, suffix}, NamespaceSeparator) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /vms/propertyfx/factory.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package propertyfx 5 | 6 | import ( 7 | "github.com/ava-labs/avalanchego/ids" 8 | "github.com/ava-labs/avalanchego/vms/fx" 9 | ) 10 | 11 | const Name = "propertyfx" 12 | 13 | var ( 14 | _ fx.Factory = (*Factory)(nil) 15 | 16 | // ID that this Fx uses when labeled 17 | ID = ids.ID{'p', 'r', 'o', 'p', 'e', 'r', 't', 'y', 'f', 'x'} 18 | ) 19 | 20 | type Factory struct{} 21 | 22 | func (*Factory) New() any { 23 | return &Fx{} 24 | } 25 | -------------------------------------------------------------------------------- /connectproto/xsvm/service.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package xsvm; 4 | 5 | option go_package = "github.com/ava-labs/avalanchego/connectproto/pb/xsvm"; 6 | 7 | service Ping { 8 | rpc Ping(PingRequest) returns (PingReply); 9 | rpc StreamPing(stream StreamPingRequest) returns (stream StreamPingReply); 10 | } 11 | 12 | message PingRequest { 13 | string message = 1; 14 | } 15 | 16 | message PingReply { 17 | string message = 1; 18 | } 19 | 20 | message StreamPingRequest { 21 | string message = 1; 22 | } 23 | 24 | message StreamPingReply { 25 | string message = 1; 26 | } 27 | -------------------------------------------------------------------------------- /vms/platformvm/txs/fee/calculator.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package fee 5 | 6 | import ( 7 | "errors" 8 | 9 | "github.com/ava-labs/avalanchego/vms/platformvm/txs" 10 | ) 11 | 12 | var ErrUnsupportedTx = errors.New("unsupported transaction type") 13 | 14 | // Calculator calculates the minimum required fee, in nAVAX, that an unsigned 15 | // transaction must pay for valid inclusion into a block. 16 | type Calculator interface { 17 | CalculateFee(tx txs.UnsignedTx) (uint64, error) 18 | } 19 | -------------------------------------------------------------------------------- /vms/proposervm/state/codec.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package state 5 | 6 | import ( 7 | "math" 8 | 9 | "github.com/ava-labs/avalanchego/codec" 10 | "github.com/ava-labs/avalanchego/codec/linearcodec" 11 | ) 12 | 13 | const CodecVersion = 0 14 | 15 | var Codec codec.Manager 16 | 17 | func init() { 18 | lc := linearcodec.NewDefault() 19 | Codec = codec.NewManager(math.MaxInt32) 20 | 21 | err := Codec.RegisterCodec(CodecVersion, lc) 22 | if err != nil { 23 | panic(err) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /api/metrics/gatherer_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package metrics 5 | 6 | import ( 7 | "github.com/prometheus/client_golang/prometheus" 8 | 9 | dto "github.com/prometheus/client_model/go" 10 | ) 11 | 12 | var counterOpts = prometheus.CounterOpts{ 13 | Name: "counter", 14 | Help: "help", 15 | } 16 | 17 | type testGatherer struct { 18 | mfs []*dto.MetricFamily 19 | err error 20 | } 21 | 22 | func (g *testGatherer) Gather() ([]*dto.MetricFamily, error) { 23 | return g.mfs, g.err 24 | } 25 | -------------------------------------------------------------------------------- /scripts/build_bootstrap_monitor.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | 5 | # Avalanchego root folder 6 | AVALANCHE_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd ) 7 | # Load the constants 8 | source "$AVALANCHE_PATH"/scripts/constants.sh 9 | source "$AVALANCHE_PATH"/scripts/git_commit.sh 10 | 11 | echo "Building bootstrap-monitor..." 12 | go build -ldflags\ 13 | "-X github.com/ava-labs/avalanchego/version.GitCommit=$git_commit $static_ld_flags"\ 14 | -o "$AVALANCHE_PATH/build/bootstrap-monitor"\ 15 | "$AVALANCHE_PATH/tests/fixture/bootstrapmonitor/cmd/"*.go 16 | -------------------------------------------------------------------------------- /vms/avm/state/mocks_generate_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package state 5 | 6 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE}mock -destination=${GOPACKAGE}mock/chain.go -mock_names=Chain=Chain . Chain 7 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE}mock -destination=${GOPACKAGE}mock/diff.go -mock_names=Diff=Diff . Diff 8 | //go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE}mock -destination=${GOPACKAGE}mock/state.go -mock_names=State=State . State 9 | -------------------------------------------------------------------------------- /vms/secp256k1fx/factory.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package secp256k1fx 5 | 6 | import ( 7 | "github.com/ava-labs/avalanchego/ids" 8 | "github.com/ava-labs/avalanchego/vms/fx" 9 | ) 10 | 11 | const Name = "secp256k1fx" 12 | 13 | var ( 14 | _ fx.Factory = (*Factory)(nil) 15 | 16 | // ID that this Fx uses when labeled 17 | ID = ids.ID{'s', 'e', 'c', 'p', '2', '5', '6', 'k', '1', 'f', 'x'} 18 | ) 19 | 20 | type Factory struct{} 21 | 22 | func (*Factory) New() any { 23 | return &Fx{} 24 | } 25 | -------------------------------------------------------------------------------- /vms/example/xsvm/cmd/chain/cmd.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package chain 5 | 6 | import ( 7 | "github.com/spf13/cobra" 8 | 9 | "github.com/ava-labs/avalanchego/vms/example/xsvm/cmd/chain/create" 10 | "github.com/ava-labs/avalanchego/vms/example/xsvm/cmd/chain/genesis" 11 | ) 12 | 13 | func Command() *cobra.Command { 14 | c := &cobra.Command{ 15 | Use: "chain", 16 | Short: "Manages XS chains", 17 | } 18 | c.AddCommand( 19 | create.Command(), 20 | genesis.Command(), 21 | ) 22 | return c 23 | } 24 | -------------------------------------------------------------------------------- /indexer/container.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package indexer 5 | 6 | import "github.com/ava-labs/avalanchego/ids" 7 | 8 | // Container is something that gets accepted 9 | // (a block, transaction or vertex) 10 | type Container struct { 11 | // ID of this container 12 | ID ids.ID `serialize:"true"` 13 | // Byte representation of this container 14 | Bytes []byte `serialize:"true"` 15 | // Unix time, in nanoseconds, at which this container was accepted by this node 16 | Timestamp int64 `serialize:"true"` 17 | } 18 | -------------------------------------------------------------------------------- /snow/networking/benchlist/benchable.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package benchlist 5 | 6 | import "github.com/ava-labs/avalanchego/ids" 7 | 8 | // Benchable is notified when a validator is benched or unbenched from a given chain 9 | type Benchable interface { 10 | // Mark that [validatorID] has been benched on the given chain 11 | Benched(chainID ids.ID, validatorID ids.NodeID) 12 | // Mark that [validatorID] has been unbenched from the given chain 13 | Unbenched(chainID ids.ID, validatorID ids.NodeID) 14 | } 15 | -------------------------------------------------------------------------------- /vms/platformvm/txs/fee/simple_calculator.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package fee 5 | 6 | import "github.com/ava-labs/avalanchego/vms/platformvm/txs" 7 | 8 | var _ Calculator = (*SimpleCalculator)(nil) 9 | 10 | type SimpleCalculator struct { 11 | txFee uint64 12 | } 13 | 14 | func NewSimpleCalculator(fee uint64) *SimpleCalculator { 15 | return &SimpleCalculator{ 16 | txFee: fee, 17 | } 18 | } 19 | 20 | func (c *SimpleCalculator) CalculateFee(txs.UnsignedTx) (uint64, error) { 21 | return c.txFee, nil 22 | } 23 | -------------------------------------------------------------------------------- /snow/engine/common/request_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package common 5 | 6 | import ( 7 | "encoding/json" 8 | "testing" 9 | 10 | "github.com/stretchr/testify/require" 11 | 12 | "github.com/ava-labs/avalanchego/ids" 13 | ) 14 | 15 | func TestRequestJSONMarshal(t *testing.T) { 16 | requestMap := map[Request]ids.ID{ 17 | { 18 | NodeID: ids.GenerateTestNodeID(), 19 | RequestID: 12345, 20 | }: ids.GenerateTestID(), 21 | } 22 | _, err := json.Marshal(requestMap) 23 | require.NoError(t, err) 24 | } 25 | -------------------------------------------------------------------------------- /vms/example/xsvm/tx/import.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package tx 5 | 6 | var _ Unsigned = (*Import)(nil) 7 | 8 | type Import struct { 9 | // Nonce provides internal chain replay protection 10 | Nonce uint64 `serialize:"true" json:"nonce"` 11 | MaxFee uint64 `serialize:"true" json:"maxFee"` 12 | // Message includes the chainIDs to provide cross chain replay protection 13 | Message []byte `serialize:"true" json:"message"` 14 | } 15 | 16 | func (i *Import) Visit(v Visitor) error { 17 | return v.Import(i) 18 | } 19 | -------------------------------------------------------------------------------- /.github/actions/install-nix/action.yml: -------------------------------------------------------------------------------- 1 | name: 'Install nix' 2 | description: 'Install nix and populate the store for the repo flake' 3 | 4 | inputs: 5 | github_token: 6 | description: "github token to authenticate with to avoid being rate-limited" 7 | default: ${{ github.token }} 8 | required: false 9 | 10 | runs: 11 | using: composite 12 | steps: 13 | - uses: cachix/install-nix-action@02a151ada4993995686f9ed4f1be7cfbb229e56f #v31 14 | with: 15 | github_access_token: ${{ inputs.github_token }} 16 | - run: nix develop --command echo "dependencies installed" 17 | shell: bash 18 | -------------------------------------------------------------------------------- /vms/platformvm/warp/constants.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package warp 5 | 6 | import "github.com/ava-labs/avalanchego/ids" 7 | 8 | // AnycastID is a special DestinationChainID that is used to indicate that the 9 | // message is intended to be able to be received by any chain. 10 | var AnycastID = ids.ID{ 11 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 12 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 13 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 14 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 15 | } 16 | -------------------------------------------------------------------------------- /x/merkledb/wait_group.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package merkledb 5 | 6 | import "sync" 7 | 8 | // waitGroup is a small wrapper of a sync.WaitGroup that avoids performing a 9 | // memory allocation when Add is never called. 10 | type waitGroup struct { 11 | wg *sync.WaitGroup 12 | } 13 | 14 | func (wg *waitGroup) Add(delta int) { 15 | if wg.wg == nil { 16 | wg.wg = new(sync.WaitGroup) 17 | } 18 | wg.wg.Add(delta) 19 | } 20 | 21 | func (wg *waitGroup) Wait() { 22 | if wg.wg != nil { 23 | wg.wg.Wait() 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /chains/registrant.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package chains 5 | 6 | import ( 7 | "github.com/ava-labs/avalanchego/snow" 8 | "github.com/ava-labs/avalanchego/snow/engine/common" 9 | ) 10 | 11 | // Registrant can register the existence of a chain 12 | type Registrant interface { 13 | // Called when a chain is created 14 | // This function is called before the chain starts processing messages 15 | // [vm] should be a vertex.DAGVM or block.ChainVM 16 | RegisterChain(chainName string, ctx *snow.ConsensusContext, vm common.VM) 17 | } 18 | -------------------------------------------------------------------------------- /tests/antithesis/Dockerfile.builder-uninstrumented: -------------------------------------------------------------------------------- 1 | # The version is supplied as a build argument rather than hard-coded 2 | # to minimize the cost of version changes. 3 | ARG GO_VERSION=INVALID # This value is not intended to be used but silences a warning 4 | 5 | FROM golang:$GO_VERSION-bookworm 6 | 7 | WORKDIR /build 8 | # Copy and download dependencies using go mod 9 | COPY go.mod . 10 | COPY go.sum . 11 | RUN go mod download 12 | 13 | # Copy the code into the container 14 | COPY . . 15 | 16 | # Ensure pre-existing builds are not available for inclusion in the final image 17 | RUN [ -d ./build ] && rm -rf ./build/* || true 18 | -------------------------------------------------------------------------------- /.github/actions/upload-tmpnet-artifact/action.yml: -------------------------------------------------------------------------------- 1 | name: 'Upload an artifact of tmpnet data' 2 | description: 'Upload an artifact of data in the ~/.tmpnet path' 3 | 4 | inputs: 5 | name: 6 | description: "the name of the artifact to upload" 7 | required: true 8 | 9 | runs: 10 | using: composite 11 | steps: 12 | - name: Upload tmpnet data 13 | uses: actions/upload-artifact@v4 14 | with: 15 | name: ${{ inputs.name }} 16 | path: | 17 | ~/.tmpnet/networks 18 | ~/.tmpnet/prometheus/prometheus.log 19 | ~/.tmpnet/promtail/promtail.log 20 | if-no-files-found: error 21 | -------------------------------------------------------------------------------- /snow/consensus/snowman/bootstrapper/noop_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package bootstrapper 5 | 6 | import ( 7 | "context" 8 | "testing" 9 | 10 | "github.com/stretchr/testify/require" 11 | ) 12 | 13 | func TestNoop(t *testing.T) { 14 | require := require.New(t) 15 | 16 | require.Empty(Noop.GetPeers(context.Background())) 17 | 18 | require.NoError(Noop.RecordOpinion(context.Background(), nodeID0, nil)) 19 | 20 | blkIDs, finalized := Noop.Result(context.Background()) 21 | require.Empty(blkIDs) 22 | require.False(finalized) 23 | } 24 | -------------------------------------------------------------------------------- /utils/slice.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package utils 5 | 6 | // DeleteIndex moves the last element in the slice to index [i] and shrinks the 7 | // size of the slice by 1. 8 | // 9 | // This is an O(1) operation that allows the removal of an element from a slice 10 | // when the order of the slice is not important. 11 | // 12 | // If [i] is out of bounds, this function will panic. 13 | func DeleteIndex[S ~[]E, E any](s S, i int) S { 14 | newSize := len(s) - 1 15 | s[i] = s[newSize] 16 | s[newSize] = Zero[E]() 17 | return s[:newSize] 18 | } 19 | -------------------------------------------------------------------------------- /x/blockdb/errors.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package blockdb 5 | 6 | import "errors" 7 | 8 | var ( 9 | ErrInvalidBlockHeight = errors.New("blockdb: invalid block height") 10 | ErrBlockEmpty = errors.New("blockdb: block is empty") 11 | ErrDatabaseClosed = errors.New("blockdb: database is closed") 12 | ErrCorrupted = errors.New("blockdb: unrecoverable corruption detected") 13 | ErrBlockTooLarge = errors.New("blockdb: block size too large") 14 | ErrBlockNotFound = errors.New("blockdb: block not found") 15 | ) 16 | -------------------------------------------------------------------------------- /chains/atomic/codec.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package atomic 5 | 6 | import ( 7 | "math" 8 | 9 | "github.com/ava-labs/avalanchego/codec" 10 | "github.com/ava-labs/avalanchego/codec/linearcodec" 11 | ) 12 | 13 | const CodecVersion = 0 14 | 15 | // Codec is used to marshal and unmarshal dbElements and chain IDs. 16 | var Codec codec.Manager 17 | 18 | func init() { 19 | lc := linearcodec.NewDefault() 20 | Codec = codec.NewManager(math.MaxInt) 21 | if err := Codec.RegisterCodec(CodecVersion, lc); err != nil { 22 | panic(err) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /vms/avm/txs/mempool/mempool.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package mempool 5 | 6 | import ( 7 | "github.com/prometheus/client_golang/prometheus" 8 | 9 | "github.com/ava-labs/avalanchego/vms/avm/txs" 10 | "github.com/ava-labs/avalanchego/vms/txs/mempool" 11 | ) 12 | 13 | func New( 14 | namespace string, 15 | registerer prometheus.Registerer, 16 | ) (mempool.Mempool[*txs.Tx], error) { 17 | metrics, err := mempool.NewMetrics(namespace, registerer) 18 | if err != nil { 19 | return nil, err 20 | } 21 | return mempool.New[*txs.Tx](metrics), nil 22 | } 23 | -------------------------------------------------------------------------------- /vms/example/xsvm/cmd/run/cmd.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package run 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/spf13/cobra" 10 | 11 | "github.com/ava-labs/avalanchego/vms/example/xsvm" 12 | "github.com/ava-labs/avalanchego/vms/rpcchainvm" 13 | ) 14 | 15 | func Command() *cobra.Command { 16 | return &cobra.Command{ 17 | Use: "xsvm", 18 | Short: "Runs an XSVM plugin", 19 | RunE: runFunc, 20 | } 21 | } 22 | 23 | func runFunc(*cobra.Command, []string) error { 24 | return rpcchainvm.Serve(context.Background(), &xsvm.VM{}) 25 | } 26 | -------------------------------------------------------------------------------- /vms/example/xsvm/state/keys.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package state 5 | 6 | var ( 7 | initializedKey = []byte{} 8 | blockPrefix = []byte{0x00} 9 | addressPrefix = []byte{0x01} 10 | chainPrefix = []byte{0x02} 11 | messagePrefix = []byte{0x03} 12 | ) 13 | 14 | func Flatten[T any](slices ...[]T) []T { 15 | var size int 16 | for _, slice := range slices { 17 | size += len(slice) 18 | } 19 | 20 | result := make([]T, 0, size) 21 | for _, slice := range slices { 22 | result = append(result, slice...) 23 | } 24 | return result 25 | } 26 | -------------------------------------------------------------------------------- /database/linkeddb/db_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package linkeddb 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/ava-labs/avalanchego/database/dbtest" 10 | "github.com/ava-labs/avalanchego/database/memdb" 11 | ) 12 | 13 | func TestInterface(t *testing.T) { 14 | for name, test := range dbtest.TestsBasic { 15 | t.Run(name, func(t *testing.T) { 16 | db := NewDefault(memdb.New()) 17 | test(t, db) 18 | }) 19 | } 20 | } 21 | 22 | func FuzzKeyValue(f *testing.F) { 23 | db := NewDefault(memdb.New()) 24 | dbtest.FuzzKeyValue(f, db) 25 | } 26 | -------------------------------------------------------------------------------- /snow/validators/connector.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package validators 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/ava-labs/avalanchego/ids" 10 | "github.com/ava-labs/avalanchego/version" 11 | ) 12 | 13 | // Connector represents a handler that is called when a connection is marked as 14 | // connected or disconnected 15 | type Connector interface { 16 | Connected( 17 | ctx context.Context, 18 | nodeID ids.NodeID, 19 | nodeVersion *version.Application, 20 | ) error 21 | Disconnected(ctx context.Context, nodeID ids.NodeID) error 22 | } 23 | -------------------------------------------------------------------------------- /simplex/codec.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package simplex 5 | 6 | import ( 7 | "math" 8 | 9 | "github.com/ava-labs/avalanchego/codec" 10 | "github.com/ava-labs/avalanchego/codec/linearcodec" 11 | "github.com/ava-labs/avalanchego/vms/platformvm/warp" 12 | ) 13 | 14 | const CodecVersion = warp.CodecVersion + 1 15 | 16 | var Codec codec.Manager 17 | 18 | func init() { 19 | lc := linearcodec.NewDefault() 20 | 21 | Codec = codec.NewManager(math.MaxInt) 22 | 23 | if err := Codec.RegisterCodec(CodecVersion, lc); err != nil { 24 | panic(err) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /version/string_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package version 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/stretchr/testify/require" 10 | ) 11 | 12 | func TestVersionsGetString(t *testing.T) { 13 | versions := Versions{ 14 | Application: "1", 15 | Database: "2", 16 | RPCChainVM: 3, 17 | Commit: "4", 18 | Go: "5", 19 | } 20 | require.Equal(t, "1 [database=2, rpcchainvm=3, commit=4, go=5]", versions.String()) 21 | versions.Commit = "" 22 | require.Equal(t, "1 [database=2, rpcchainvm=3, go=5]", versions.String()) 23 | } 24 | -------------------------------------------------------------------------------- /vms/example/xsvm/warp.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package xsvm 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/ava-labs/avalanchego/network/p2p/acp118" 10 | "github.com/ava-labs/avalanchego/snow/engine/common" 11 | "github.com/ava-labs/avalanchego/vms/platformvm/warp" 12 | ) 13 | 14 | var _ acp118.Verifier = (*acp118Verifier)(nil) 15 | 16 | // acp118Verifier allows signing all warp messages 17 | type acp118Verifier struct{} 18 | 19 | func (acp118Verifier) Verify(context.Context, *warp.UnsignedMessage, []byte) *common.AppError { 20 | return nil 21 | } 22 | -------------------------------------------------------------------------------- /utils/sampler/uniform_benchmark_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package sampler 5 | 6 | import ( 7 | "fmt" 8 | "testing" 9 | ) 10 | 11 | func BenchmarkUniform(b *testing.B) { 12 | sizes := []uint64{ 13 | 30, 14 | 35, 15 | 500, 16 | 10000, 17 | 100000, 18 | } 19 | for _, size := range sizes { 20 | b.Run(fmt.Sprintf("%d elements uniformly", size), func(b *testing.B) { 21 | s := NewUniform() 22 | 23 | s.Initialize(size) 24 | 25 | b.ResetTimer() 26 | for i := 0; i < b.N; i++ { 27 | _, _ = s.Sample(30) 28 | } 29 | }) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /x/merkledb/wait_group_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package merkledb 5 | 6 | import "testing" 7 | 8 | func Benchmark_WaitGroup_Wait(b *testing.B) { 9 | for i := 0; i < b.N; i++ { 10 | var wg waitGroup 11 | wg.Wait() 12 | } 13 | } 14 | 15 | func Benchmark_WaitGroup_Add(b *testing.B) { 16 | for i := 0; i < b.N; i++ { 17 | var wg waitGroup 18 | wg.Add(1) 19 | } 20 | } 21 | 22 | func Benchmark_WaitGroup_AddDoneWait(b *testing.B) { 23 | for i := 0; i < b.N; i++ { 24 | var wg waitGroup 25 | wg.Add(1) 26 | wg.wg.Done() 27 | wg.Wait() 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /x/sync/protoutils/utils.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package protoutils 5 | 6 | import ( 7 | "github.com/ava-labs/avalanchego/utils/maybe" 8 | 9 | pb "github.com/ava-labs/avalanchego/proto/pb/sync" 10 | ) 11 | 12 | func MaybeToProto(m maybe.Maybe[[]byte]) *pb.MaybeBytes { 13 | if m.IsNothing() { 14 | return nil 15 | } 16 | return &pb.MaybeBytes{ 17 | Value: m.Value(), 18 | } 19 | } 20 | 21 | func ProtoToMaybe(mb *pb.MaybeBytes) maybe.Maybe[[]byte] { 22 | if mb == nil { 23 | return maybe.Nothing[[]byte]() 24 | } 25 | return maybe.Some(mb.Value) 26 | } 27 | -------------------------------------------------------------------------------- /vms/platformvm/block/visitor.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package block 5 | 6 | type Visitor interface { 7 | BanffAbortBlock(*BanffAbortBlock) error 8 | BanffCommitBlock(*BanffCommitBlock) error 9 | BanffProposalBlock(*BanffProposalBlock) error 10 | BanffStandardBlock(*BanffStandardBlock) error 11 | 12 | ApricotAbortBlock(*ApricotAbortBlock) error 13 | ApricotCommitBlock(*ApricotCommitBlock) error 14 | ApricotProposalBlock(*ApricotProposalBlock) error 15 | ApricotStandardBlock(*ApricotStandardBlock) error 16 | ApricotAtomicBlock(*ApricotAtomicBlock) error 17 | } 18 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_spec.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature specification 3 | about: Discussion on design and implementation of new features for avalanchego. 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Context and scope** 11 | Include a short description of the context and scope of the suggested feature. 12 | Include goals the change will accomplish if relevant. 13 | 14 | **Discussion and alternatives** 15 | Include a description of the changes to be made to the code along with alternatives 16 | that were considered, including pro/con analysis where relevant. 17 | 18 | **Open questions** 19 | Questions that are still being discussed. 20 | -------------------------------------------------------------------------------- /proto/io/writer/writer.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package io.writer; 4 | 5 | option go_package = "github.com/ava-labs/avalanchego/proto/pb/io/writer"; 6 | 7 | // Writer see: io.Writer https://pkg.go.dev/io#Writer 8 | service Writer { 9 | // Write writes len(p) bytes from p to the underlying data stream. 10 | rpc Write(WriteRequest) returns (WriteResponse); 11 | } 12 | 13 | message WriteRequest { 14 | // payload is the write request in bytes 15 | bytes payload = 1; 16 | } 17 | 18 | message WriteResponse { 19 | // written is the length of payload in bytes 20 | int32 written = 1; 21 | // error is an error message 22 | optional string error = 2; 23 | } 24 | -------------------------------------------------------------------------------- /vms/platformvm/warp/codec.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package warp 5 | 6 | import ( 7 | "errors" 8 | "math" 9 | 10 | "github.com/ava-labs/avalanchego/codec" 11 | "github.com/ava-labs/avalanchego/codec/linearcodec" 12 | ) 13 | 14 | const CodecVersion = 0 15 | 16 | var Codec codec.Manager 17 | 18 | func init() { 19 | Codec = codec.NewManager(math.MaxInt) 20 | lc := linearcodec.NewDefault() 21 | 22 | err := errors.Join( 23 | lc.RegisterType(&BitSetSignature{}), 24 | Codec.RegisterCodec(CodecVersion, lc), 25 | ) 26 | if err != nil { 27 | panic(err) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /.github/workflows/labels.yml: -------------------------------------------------------------------------------- 1 | name: labels 2 | on: 3 | push: 4 | branches: 5 | - master 6 | paths: 7 | - .github/labels.yml 8 | - .github/workflows/labels.yml 9 | pull_request: # dry run only 10 | paths: 11 | - .github/labels.yml 12 | - .github/workflows/labels.yml 13 | 14 | jobs: 15 | labeler: 16 | permissions: 17 | contents: read 18 | issues: write 19 | runs-on: ubuntu-latest 20 | steps: 21 | - uses: actions/checkout@v4 22 | - uses: crazy-max/ghaction-github-labeler@31674a3852a9074f2086abcf1c53839d466a47e7 #v5.2.0 23 | with: 24 | dry-run: ${{ github.event_name == 'pull_request' }} 25 | -------------------------------------------------------------------------------- /vms/proposervm/summary/codec.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package summary 5 | 6 | import ( 7 | "errors" 8 | "math" 9 | 10 | "github.com/ava-labs/avalanchego/codec" 11 | "github.com/ava-labs/avalanchego/codec/linearcodec" 12 | ) 13 | 14 | const CodecVersion = 0 15 | 16 | var ( 17 | Codec codec.Manager 18 | 19 | errWrongCodecVersion = errors.New("wrong codec version") 20 | ) 21 | 22 | func init() { 23 | lc := linearcodec.NewDefault() 24 | Codec = codec.NewManager(math.MaxInt32) 25 | if err := Codec.RegisterCodec(CodecVersion, lc); err != nil { 26 | panic(err) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /snow/consensus/snowman/bootstrapper/noop.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package bootstrapper 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/ava-labs/avalanchego/ids" 10 | "github.com/ava-labs/avalanchego/utils/set" 11 | ) 12 | 13 | var Noop Poll = noop{} 14 | 15 | type noop struct{} 16 | 17 | func (noop) GetPeers(context.Context) set.Set[ids.NodeID] { 18 | return nil 19 | } 20 | 21 | func (noop) RecordOpinion(context.Context, ids.NodeID, set.Set[ids.ID]) error { 22 | return nil 23 | } 24 | 25 | func (noop) Result(context.Context) ([]ids.ID, bool) { 26 | return nil, false 27 | } 28 | -------------------------------------------------------------------------------- /snow/engine/avalanche/bootstrap/queue/job.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package queue 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/ava-labs/avalanchego/ids" 10 | "github.com/ava-labs/avalanchego/utils/set" 11 | ) 12 | 13 | // Job defines the interface required to be placed on the job queue. 14 | type Job interface { 15 | ID() ids.ID 16 | MissingDependencies(context.Context) (set.Set[ids.ID], error) 17 | // Returns true if this job has at least 1 missing dependency 18 | HasMissingDependencies(context.Context) (bool, error) 19 | Execute(context.Context) error 20 | Bytes() []byte 21 | } 22 | -------------------------------------------------------------------------------- /snow/snowtest/status.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package snowtest 5 | 6 | type Status int 7 | 8 | // [Undecided] means the operation hasn't been decided yet 9 | // [Accepted] means the operation was accepted 10 | // [Rejected] means the operation will never be accepted 11 | const ( 12 | Undecided Status = iota 13 | Accepted 14 | Rejected 15 | ) 16 | 17 | func (s Status) String() string { 18 | switch s { 19 | case Undecided: 20 | return "Undecided" 21 | case Accepted: 22 | return "Accepted" 23 | case Rejected: 24 | return "Rejected" 25 | default: 26 | return "Unknown" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /vms/platformvm/factory.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package platformvm 5 | 6 | import ( 7 | "github.com/ava-labs/avalanchego/utils/logging" 8 | "github.com/ava-labs/avalanchego/vms" 9 | "github.com/ava-labs/avalanchego/vms/platformvm/config" 10 | ) 11 | 12 | var _ vms.Factory = (*Factory)(nil) 13 | 14 | // Factory can create new instances of the Platform Chain 15 | type Factory struct { 16 | config.Internal 17 | } 18 | 19 | // New returns a new instance of the Platform Chain 20 | func (f *Factory) New(logging.Logger) (interface{}, error) { 21 | return &VM{Internal: f.Internal}, nil 22 | } 23 | -------------------------------------------------------------------------------- /utils/compression/no_compressor_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package compression 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/stretchr/testify/require" 10 | ) 11 | 12 | func TestNoCompressor(t *testing.T) { 13 | require := require.New(t) 14 | 15 | data := []byte{1, 2, 3} 16 | compressor := NewNoCompressor() 17 | compressedBytes, err := compressor.Compress(data) 18 | require.NoError(err) 19 | require.Equal(data, compressedBytes) 20 | 21 | decompressedBytes, err := compressor.Decompress(compressedBytes) 22 | require.NoError(err) 23 | require.Equal(data, decompressedBytes) 24 | } 25 | -------------------------------------------------------------------------------- /utils/filesystem/rename.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package filesystem 5 | 6 | import ( 7 | "errors" 8 | "io/fs" 9 | "os" 10 | ) 11 | 12 | // Renames the file "a" to "b" iff "a" exists. 13 | // It returns "true" and no error, if rename were successful. 14 | // It returns "false" and no error, if the file "a" does not exist. 15 | // It returns "false" and an error, if rename failed. 16 | func RenameIfExists(a, b string) (renamed bool, err error) { 17 | err = os.Rename(a, b) 18 | renamed = err == nil 19 | if errors.Is(err, fs.ErrNotExist) { 20 | err = nil 21 | } 22 | return renamed, err 23 | } 24 | -------------------------------------------------------------------------------- /proto/vm/runtime/runtime.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package vm.runtime; 4 | 5 | import "google/protobuf/empty.proto"; 6 | 7 | option go_package = "github.com/ava-labs/avalanchego/proto/pb/vm/manager"; 8 | 9 | // Manages the lifecycle of a subnet VM process. 10 | service Runtime { 11 | // Initialize a VM Runtime. 12 | rpc Initialize(InitializeRequest) returns (google.protobuf.Empty); 13 | } 14 | 15 | message InitializeRequest { 16 | // ProtocolVersion is used to identify incompatibilities with AvalancheGo and a VM. 17 | uint32 protocol_version = 1; 18 | // Address of the gRPC server endpoint serving the handshake logic. 19 | // Example: 127.0.0.1:50001 20 | string addr = 2; 21 | } 22 | -------------------------------------------------------------------------------- /vms/proposervm/summary/parse.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package summary 5 | 6 | import ( 7 | "fmt" 8 | 9 | "github.com/ava-labs/avalanchego/utils/hashing" 10 | ) 11 | 12 | func Parse(bytes []byte) (StateSummary, error) { 13 | summary := stateSummary{ 14 | id: hashing.ComputeHash256Array(bytes), 15 | bytes: bytes, 16 | } 17 | version, err := Codec.Unmarshal(bytes, &summary) 18 | if err != nil { 19 | return nil, fmt.Errorf("could not unmarshal summary due to: %w", err) 20 | } 21 | if version != CodecVersion { 22 | return nil, errWrongCodecVersion 23 | } 24 | return &summary, nil 25 | } 26 | -------------------------------------------------------------------------------- /snow/engine/enginetest/timer.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package enginetest 5 | 6 | import ( 7 | "testing" 8 | "time" 9 | 10 | "github.com/stretchr/testify/require" 11 | ) 12 | 13 | // Timer is a test timer 14 | type Timer struct { 15 | T *testing.T 16 | 17 | CantRegisterTimout bool 18 | 19 | RegisterTimeoutF func(time.Duration) 20 | } 21 | 22 | func (t *Timer) RegisterTimeout(delay time.Duration) { 23 | if t.RegisterTimeoutF != nil { 24 | t.RegisterTimeoutF(delay) 25 | } else if t.CantRegisterTimout && t.T != nil { 26 | require.FailNow(t.T, "Unexpectedly called RegisterTimeout") 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /utils/json/uint8.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package json 5 | 6 | import "strconv" 7 | 8 | type Uint8 uint8 9 | 10 | func (u Uint8) MarshalJSON() ([]byte, error) { 11 | return []byte(`"` + strconv.FormatUint(uint64(u), 10) + `"`), nil 12 | } 13 | 14 | func (u *Uint8) UnmarshalJSON(b []byte) error { 15 | str := string(b) 16 | if str == Null { 17 | return nil 18 | } 19 | if len(str) >= 2 { 20 | if lastIndex := len(str) - 1; str[0] == '"' && str[lastIndex] == '"' { 21 | str = str[1:lastIndex] 22 | } 23 | } 24 | val, err := strconv.ParseUint(str, 10, 8) 25 | *u = Uint8(val) 26 | return err 27 | } 28 | -------------------------------------------------------------------------------- /utils/perms/chmod.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package perms 5 | 6 | import ( 7 | "errors" 8 | "os" 9 | "path/filepath" 10 | ) 11 | 12 | // ChmodR sets the permissions of all directories and optionally files to [perm] 13 | // permissions. 14 | func ChmodR(dir string, dirOnly bool, perm os.FileMode) error { 15 | if _, err := os.Stat(dir); errors.Is(err, os.ErrNotExist) { 16 | return nil 17 | } 18 | return filepath.Walk(dir, func(name string, info os.FileInfo, err error) error { 19 | if err != nil || (dirOnly && !info.IsDir()) { 20 | return err 21 | } 22 | return os.Chmod(name, perm) 23 | }) 24 | } 25 | -------------------------------------------------------------------------------- /.github/workflows/buf-push.yml: -------------------------------------------------------------------------------- 1 | name: buf-push 2 | 3 | on: 4 | push: 5 | tags: 6 | - "*" 7 | branches: 8 | - master 9 | - dev 10 | paths: 11 | - "proto/**" 12 | 13 | jobs: 14 | push: 15 | runs-on: ubuntu-latest 16 | steps: 17 | - uses: actions/checkout@v4 18 | - uses: bufbuild/buf-action@dfda68eacb65895184c76b9ae522b977636a2c47 #v1.1.4 19 | with: 20 | input: "proto" 21 | # Breaking changes are managed by the rpcchainvm protocol version. 22 | breaking: false 23 | token: ${{ secrets.BUF_TOKEN }} 24 | # This version should match the version installed in the nix dev shell 25 | version: 1.47.2 26 | -------------------------------------------------------------------------------- /api/health/checker.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package health 5 | 6 | import "context" 7 | 8 | var _ Checker = CheckerFunc(nil) 9 | 10 | // Checker can have its health checked 11 | type Checker interface { 12 | // HealthCheck returns health check results and, if not healthy, a non-nil 13 | // error 14 | // 15 | // It is expected that the results are json marshallable. 16 | HealthCheck(context.Context) (interface{}, error) 17 | } 18 | 19 | type CheckerFunc func(context.Context) (interface{}, error) 20 | 21 | func (f CheckerFunc) HealthCheck(ctx context.Context) (interface{}, error) { 22 | return f(ctx) 23 | } 24 | -------------------------------------------------------------------------------- /snow/engine/common/state_syncer.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package common 5 | 6 | import "context" 7 | 8 | // StateSyncer controls the selection and verification of state summaries 9 | // to drive VM state syncing. It collects the latest state summaries and elicit 10 | // votes on them, making sure that a qualified majority of nodes support the 11 | // selected state summary. 12 | type StateSyncer interface { 13 | Engine 14 | 15 | // IsEnabled returns true if the underlying VM wants to perform state sync. 16 | // Any returned error will be considered fatal. 17 | IsEnabled(context.Context) (bool, error) 18 | } 19 | -------------------------------------------------------------------------------- /vms/example/xsvm/cmd/issue/cmd.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package issue 5 | 6 | import ( 7 | "github.com/spf13/cobra" 8 | 9 | "github.com/ava-labs/avalanchego/vms/example/xsvm/cmd/issue/export" 10 | "github.com/ava-labs/avalanchego/vms/example/xsvm/cmd/issue/importtx" 11 | "github.com/ava-labs/avalanchego/vms/example/xsvm/cmd/issue/transfer" 12 | ) 13 | 14 | func Command() *cobra.Command { 15 | c := &cobra.Command{ 16 | Use: "issue", 17 | Short: "Issues transactions", 18 | } 19 | c.AddCommand( 20 | transfer.Command(), 21 | export.Command(), 22 | importtx.Command(), 23 | ) 24 | return c 25 | } 26 | -------------------------------------------------------------------------------- /utils/json/uint16.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package json 5 | 6 | import "strconv" 7 | 8 | type Uint16 uint16 9 | 10 | func (u Uint16) MarshalJSON() ([]byte, error) { 11 | return []byte(`"` + strconv.FormatUint(uint64(u), 10) + `"`), nil 12 | } 13 | 14 | func (u *Uint16) UnmarshalJSON(b []byte) error { 15 | str := string(b) 16 | if str == Null { 17 | return nil 18 | } 19 | if len(str) >= 2 { 20 | if lastIndex := len(str) - 1; str[0] == '"' && str[lastIndex] == '"' { 21 | str = str[1:lastIndex] 22 | } 23 | } 24 | val, err := strconv.ParseUint(str, 10, 16) 25 | *u = Uint16(val) 26 | return err 27 | } 28 | -------------------------------------------------------------------------------- /utils/json/uint32.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package json 5 | 6 | import "strconv" 7 | 8 | type Uint32 uint32 9 | 10 | func (u Uint32) MarshalJSON() ([]byte, error) { 11 | return []byte(`"` + strconv.FormatUint(uint64(u), 10) + `"`), nil 12 | } 13 | 14 | func (u *Uint32) UnmarshalJSON(b []byte) error { 15 | str := string(b) 16 | if str == Null { 17 | return nil 18 | } 19 | if len(str) >= 2 { 20 | if lastIndex := len(str) - 1; str[0] == '"' && str[lastIndex] == '"' { 21 | str = str[1:lastIndex] 22 | } 23 | } 24 | val, err := strconv.ParseUint(str, 10, 32) 25 | *u = Uint32(val) 26 | return err 27 | } 28 | -------------------------------------------------------------------------------- /utils/json/uint64.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package json 5 | 6 | import "strconv" 7 | 8 | type Uint64 uint64 9 | 10 | func (u Uint64) MarshalJSON() ([]byte, error) { 11 | return []byte(`"` + strconv.FormatUint(uint64(u), 10) + `"`), nil 12 | } 13 | 14 | func (u *Uint64) UnmarshalJSON(b []byte) error { 15 | str := string(b) 16 | if str == Null { 17 | return nil 18 | } 19 | if len(str) >= 2 { 20 | if lastIndex := len(str) - 1; str[0] == '"' && str[lastIndex] == '"' { 21 | str = str[1:lastIndex] 22 | } 23 | } 24 | val, err := strconv.ParseUint(str, 10, 64) 25 | *u = Uint64(val) 26 | return err 27 | } 28 | -------------------------------------------------------------------------------- /snow/uptime/no_op_calculator.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package uptime 5 | 6 | import ( 7 | "time" 8 | 9 | "github.com/ava-labs/avalanchego/ids" 10 | ) 11 | 12 | var NoOpCalculator Calculator = noOpCalculator{} 13 | 14 | type noOpCalculator struct{} 15 | 16 | func (noOpCalculator) CalculateUptime(ids.NodeID) (time.Duration, time.Time, error) { 17 | return 0, time.Time{}, nil 18 | } 19 | 20 | func (noOpCalculator) CalculateUptimePercent(ids.NodeID) (float64, error) { 21 | return 0, nil 22 | } 23 | 24 | func (noOpCalculator) CalculateUptimePercentFrom(ids.NodeID, time.Time) (float64, error) { 25 | return 0, nil 26 | } 27 | -------------------------------------------------------------------------------- /utils/beacon/beacon.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package beacon 5 | 6 | import ( 7 | "net/netip" 8 | 9 | "github.com/ava-labs/avalanchego/ids" 10 | ) 11 | 12 | var _ Beacon = (*beacon)(nil) 13 | 14 | type Beacon interface { 15 | ID() ids.NodeID 16 | IP() netip.AddrPort 17 | } 18 | 19 | type beacon struct { 20 | id ids.NodeID 21 | ip netip.AddrPort 22 | } 23 | 24 | func New(id ids.NodeID, ip netip.AddrPort) Beacon { 25 | return &beacon{ 26 | id: id, 27 | ip: ip, 28 | } 29 | } 30 | 31 | func (b *beacon) ID() ids.NodeID { 32 | return b.id 33 | } 34 | 35 | func (b *beacon) IP() netip.AddrPort { 36 | return b.ip 37 | } 38 | -------------------------------------------------------------------------------- /utils/crypto/keychain/ledger.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package keychain 5 | 6 | import ( 7 | "github.com/ava-labs/avalanchego/ids" 8 | "github.com/ava-labs/avalanchego/version" 9 | ) 10 | 11 | // Ledger interface for the ledger wrapper 12 | type Ledger interface { 13 | Version() (v *version.Semantic, err error) 14 | Address(displayHRP string, addressIndex uint32) (ids.ShortID, error) 15 | Addresses(addressIndices []uint32) ([]ids.ShortID, error) 16 | SignHash(hash []byte, addressIndices []uint32) ([][]byte, error) 17 | Sign(unsignedTxBytes []byte, addressIndices []uint32) ([][]byte, error) 18 | Disconnect() error 19 | } 20 | -------------------------------------------------------------------------------- /vms/proposervm/summary/build_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package summary 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/stretchr/testify/require" 10 | ) 11 | 12 | func TestBuild(t *testing.T) { 13 | require := require.New(t) 14 | 15 | forkHeight := uint64(2022) 16 | block := []byte("blockBytes") 17 | coreSummary := []byte("coreSummary") 18 | builtSummary, err := Build(forkHeight, block, coreSummary) 19 | require.NoError(err) 20 | 21 | require.Equal(builtSummary.ForkHeight(), forkHeight) 22 | require.Equal(builtSummary.BlockBytes(), block) 23 | require.Equal(builtSummary.InnerSummaryBytes(), coreSummary) 24 | } 25 | -------------------------------------------------------------------------------- /snow/consensus/snowman/oracle_block.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package snowman 5 | 6 | import ( 7 | "context" 8 | "errors" 9 | ) 10 | 11 | var ErrNotOracle = errors.New("block isn't an oracle") 12 | 13 | // OracleBlock is a block that only has two valid children. The children should 14 | // be returned in preferential order. 15 | // 16 | // This ordering does not need to be deterministically created from the chain 17 | // state. 18 | type OracleBlock interface { 19 | // Options returns the possible children of this block in the order this 20 | // validator prefers the blocks. 21 | Options(context.Context) ([2]Block, error) 22 | } 23 | -------------------------------------------------------------------------------- /snow/engine/common/bootstrap_tracker.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package common 5 | 6 | import "github.com/ava-labs/avalanchego/ids" 7 | 8 | // BootstrapTracker describes the standard interface for tracking the status of 9 | // a subnet bootstrapping 10 | type BootstrapTracker interface { 11 | // Returns true iff done bootstrapping 12 | IsBootstrapped() bool 13 | 14 | // Bootstrapped marks the named chain as being bootstrapped 15 | Bootstrapped(chainID ids.ID) 16 | 17 | // AllBootstrapped returns a channel that is closed when all chains in this 18 | // subnet have been bootstrapped 19 | AllBootstrapped() <-chan struct{} 20 | } 21 | -------------------------------------------------------------------------------- /utils/json/float32.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package json 5 | 6 | import "strconv" 7 | 8 | type Float32 float32 9 | 10 | func (f Float32) MarshalJSON() ([]byte, error) { 11 | return []byte(`"` + strconv.FormatFloat(float64(f), byte('f'), 4, 32) + `"`), nil 12 | } 13 | 14 | func (f *Float32) UnmarshalJSON(b []byte) error { 15 | str := string(b) 16 | if str == Null { 17 | return nil 18 | } 19 | if len(str) >= 2 { 20 | if lastIndex := len(str) - 1; str[0] == '"' && str[lastIndex] == '"' { 21 | str = str[1:lastIndex] 22 | } 23 | } 24 | val, err := strconv.ParseFloat(str, 32) 25 | *f = Float32(val) 26 | return err 27 | } 28 | -------------------------------------------------------------------------------- /utils/json/float64.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package json 5 | 6 | import "strconv" 7 | 8 | type Float64 float64 9 | 10 | func (f Float64) MarshalJSON() ([]byte, error) { 11 | return []byte(`"` + strconv.FormatFloat(float64(f), byte('f'), 4, 64) + `"`), nil 12 | } 13 | 14 | func (f *Float64) UnmarshalJSON(b []byte) error { 15 | str := string(b) 16 | if str == Null { 17 | return nil 18 | } 19 | if len(str) >= 2 { 20 | if lastIndex := len(str) - 1; str[0] == '"' && str[lastIndex] == '"' { 21 | str = str[1:lastIndex] 22 | } 23 | } 24 | val, err := strconv.ParseFloat(str, 64) 25 | *f = Float64(val) 26 | return err 27 | } 28 | -------------------------------------------------------------------------------- /vms/example/xsvm/tx/codec.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package tx 5 | 6 | import ( 7 | "errors" 8 | "math" 9 | 10 | "github.com/ava-labs/avalanchego/codec" 11 | "github.com/ava-labs/avalanchego/codec/linearcodec" 12 | ) 13 | 14 | const CodecVersion = 0 15 | 16 | var Codec codec.Manager 17 | 18 | func init() { 19 | c := linearcodec.NewDefault() 20 | Codec = codec.NewManager(math.MaxInt32) 21 | 22 | err := errors.Join( 23 | c.RegisterType(&Transfer{}), 24 | c.RegisterType(&Export{}), 25 | c.RegisterType(&Import{}), 26 | Codec.RegisterCodec(CodecVersion, c), 27 | ) 28 | if err != nil { 29 | panic(err) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /cache/empty.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package cache 5 | 6 | import "github.com/ava-labs/avalanchego/utils" 7 | 8 | var _ Cacher[struct{}, struct{}] = (*Empty[struct{}, struct{}])(nil) 9 | 10 | // Empty is a cache that doesn't store anything. 11 | type Empty[K any, V any] struct{} 12 | 13 | func (*Empty[K, V]) Put(K, V) {} 14 | 15 | func (*Empty[K, V]) Get(K) (V, bool) { 16 | return utils.Zero[V](), false 17 | } 18 | 19 | func (*Empty[K, _]) Evict(K) {} 20 | 21 | func (*Empty[_, _]) Flush() {} 22 | 23 | func (*Empty[_, _]) Len() int { 24 | return 0 25 | } 26 | 27 | func (*Empty[_, _]) PortionFilled() float64 { 28 | return 0 29 | } 30 | -------------------------------------------------------------------------------- /utils/iterator/iterator.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package iterator 5 | 6 | // Iterator defines an interface for iterating over a set. 7 | type Iterator[T any] interface { 8 | // Next attempts to move the iterator to the next element in the set. It 9 | // returns false once there are no more elements to return. 10 | Next() bool 11 | 12 | // Value returns the value of the current element. Value should only be called 13 | // after a call to Next which returned true. 14 | Value() T 15 | 16 | // Release any resources associated with the iterator. This must be called 17 | // after the iterator is no longer needed. 18 | Release() 19 | } 20 | -------------------------------------------------------------------------------- /snow/engine/avalanche/vertex/vertextest/manager.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package vertextest 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/ava-labs/avalanchego/snow/engine/avalanche/vertex" 10 | ) 11 | 12 | var _ vertex.Manager = (*Manager)(nil) 13 | 14 | type Manager struct { 15 | Builder 16 | Parser 17 | Storage 18 | } 19 | 20 | func NewManager(t *testing.T) *Manager { 21 | return &Manager{ 22 | Builder: Builder{T: t}, 23 | Parser: Parser{T: t}, 24 | Storage: Storage{T: t}, 25 | } 26 | } 27 | 28 | func (m *Manager) Default(cant bool) { 29 | m.Builder.Default(cant) 30 | m.Parser.Default(cant) 31 | m.Storage.Default(cant) 32 | } 33 | -------------------------------------------------------------------------------- /utils/formatting/address/converter.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package address 5 | 6 | import "github.com/ava-labs/avalanchego/ids" 7 | 8 | func ParseToID(addrStr string) (ids.ShortID, error) { 9 | _, _, addrBytes, err := Parse(addrStr) 10 | if err != nil { 11 | return ids.ShortID{}, err 12 | } 13 | return ids.ToShortID(addrBytes) 14 | } 15 | 16 | func ParseToIDs(addrStrs []string) ([]ids.ShortID, error) { 17 | var err error 18 | addrs := make([]ids.ShortID, len(addrStrs)) 19 | for i, addrStr := range addrStrs { 20 | addrs[i], err = ParseToID(addrStr) 21 | if err != nil { 22 | return nil, err 23 | } 24 | } 25 | return addrs, nil 26 | } 27 | -------------------------------------------------------------------------------- /codec/linearcodec/codec_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package linearcodec 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/ava-labs/avalanchego/codec" 10 | "github.com/ava-labs/avalanchego/codec/codectest" 11 | ) 12 | 13 | func TestVectors(t *testing.T) { 14 | codectest.RunAll(t, func() codec.GeneralCodec { 15 | return NewDefault() 16 | }) 17 | } 18 | 19 | func TestMultipleTags(t *testing.T) { 20 | codectest.RunAllMultipleTags(t, func() codec.GeneralCodec { 21 | return New([]string{"tag1", "tag2"}) 22 | }) 23 | } 24 | 25 | func FuzzStructUnmarshalLinearCodec(f *testing.F) { 26 | c := NewDefault() 27 | codectest.FuzzStructUnmarshal(c, f) 28 | } 29 | -------------------------------------------------------------------------------- /utils/crypto/bls/ciphersuite.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package bls 5 | 6 | type Ciphersuite int 7 | 8 | const ( 9 | CiphersuiteSignature Ciphersuite = iota 10 | CiphersuiteProofOfPossession 11 | ) 12 | 13 | var ciphersuiteStrings = [...]string{ 14 | "BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_", 15 | "BLS_POP_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_", 16 | } 17 | 18 | var ciphersuiteBytes = [...][]byte{ 19 | []byte(ciphersuiteStrings[0]), 20 | []byte(ciphersuiteStrings[1]), 21 | } 22 | 23 | func (c Ciphersuite) String() string { 24 | return ciphersuiteStrings[c] 25 | } 26 | 27 | func (c Ciphersuite) Bytes() []byte { 28 | return ciphersuiteBytes[c] 29 | } 30 | -------------------------------------------------------------------------------- /utils/math/sync_averager.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package math 5 | 6 | import ( 7 | "sync" 8 | "time" 9 | ) 10 | 11 | type syncAverager struct { 12 | lock sync.RWMutex 13 | averager Averager 14 | } 15 | 16 | func NewSyncAverager(averager Averager) Averager { 17 | return &syncAverager{ 18 | averager: averager, 19 | } 20 | } 21 | 22 | func (a *syncAverager) Observe(value float64, currentTime time.Time) { 23 | a.lock.Lock() 24 | defer a.lock.Unlock() 25 | 26 | a.averager.Observe(value, currentTime) 27 | } 28 | 29 | func (a *syncAverager) Read() float64 { 30 | a.lock.RLock() 31 | defer a.lock.RUnlock() 32 | 33 | return a.averager.Read() 34 | } 35 | -------------------------------------------------------------------------------- /utils/perms/create.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package perms 5 | 6 | import ( 7 | "errors" 8 | "os" 9 | ) 10 | 11 | // Create a file at [filename] that has [perm] permissions. 12 | func Create(filename string, perm os.FileMode) (*os.File, error) { 13 | if info, err := os.Stat(filename); err == nil { 14 | if info.Mode() != perm { 15 | // The file currently has the wrong permissions, so update them. 16 | if err := os.Chmod(filename, perm); err != nil { 17 | return nil, err 18 | } 19 | } 20 | } else if !errors.Is(err, os.ErrNotExist) { 21 | return nil, err 22 | } 23 | return os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC, perm) 24 | } 25 | -------------------------------------------------------------------------------- /vms/avm/config.md: -------------------------------------------------------------------------------- 1 | In order to specify a config for the X-Chain, a JSON config file should be 2 | placed at `{chain-config-dir}/X/config.json`. 3 | 4 | For example if `chain-config-dir` has the default value which is 5 | `$HOME/.avalanchego/configs/chains`, then `config.json` can be placed at 6 | `$HOME/.avalanchego/configs/chains/X/config.json`. 7 | 8 | This allows you to specify a config to be passed into the X-Chain. The default 9 | values for this config are: 10 | 11 | ```json 12 | { 13 | "checksums-enabled": false 14 | } 15 | ``` 16 | 17 | Default values are overridden only if explicitly specified in the config. 18 | 19 | The parameters are as follows: 20 | 21 | ### `checksums-enabled` 22 | 23 | _Boolean_ 24 | 25 | Enables checksums if set to `true`. 26 | -------------------------------------------------------------------------------- /vms/avm/txs/txstest/context.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package txstest 5 | 6 | import ( 7 | "github.com/ava-labs/avalanchego/ids" 8 | "github.com/ava-labs/avalanchego/snow" 9 | "github.com/ava-labs/avalanchego/vms/avm/config" 10 | "github.com/ava-labs/avalanchego/wallet/chain/x/builder" 11 | ) 12 | 13 | func newContext( 14 | ctx *snow.Context, 15 | cfg *config.Config, 16 | feeAssetID ids.ID, 17 | ) *builder.Context { 18 | return &builder.Context{ 19 | NetworkID: ctx.NetworkID, 20 | BlockchainID: ctx.XChainID, 21 | AVAXAssetID: feeAssetID, 22 | BaseTxFee: cfg.TxFee, 23 | CreateAssetTxFee: cfg.CreateAssetTxFee, 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /scripts/shellcheck.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | 5 | # This script can also be used to correct the problems detected by shellcheck by invoking as follows: 6 | # 7 | # ./scripts/tests.shellcheck.sh -f diff | git apply 8 | # 9 | 10 | if ! [[ "$0" =~ scripts/shellcheck.sh ]]; then 11 | echo "must be run from repository root" 12 | exit 255 13 | fi 14 | 15 | # `find *` is the simplest way to ensure find does not include a 16 | # leading `.` in filenames it emits. A leading `.` will prevent the 17 | # use of `git apply` to fix reported shellcheck issues. This is 18 | # compatible with both macos and linux (unlike the use of -printf). 19 | # 20 | # shellcheck disable=SC2035 21 | find * -name "*.sh" -type f -print0 | xargs -0 shellcheck "${@}" 22 | -------------------------------------------------------------------------------- /codec/hierarchycodec/codec_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package hierarchycodec 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/ava-labs/avalanchego/codec" 10 | "github.com/ava-labs/avalanchego/codec/codectest" 11 | ) 12 | 13 | func TestVectors(t *testing.T) { 14 | codectest.RunAll(t, func() codec.GeneralCodec { 15 | return NewDefault() 16 | }) 17 | } 18 | 19 | func TestMultipleTags(t *testing.T) { 20 | codectest.RunAllMultipleTags(t, func() codec.GeneralCodec { 21 | return New([]string{"tag1", "tag2"}) 22 | }) 23 | } 24 | 25 | func FuzzStructUnmarshalHierarchyCodec(f *testing.F) { 26 | c := NewDefault() 27 | codectest.FuzzStructUnmarshal(c, f) 28 | } 29 | -------------------------------------------------------------------------------- /vms/components/verify/verification_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package verify 5 | 6 | import ( 7 | "errors" 8 | "testing" 9 | 10 | "github.com/stretchr/testify/require" 11 | ) 12 | 13 | var errTest = errors.New("non-nil error") 14 | 15 | type testVerifiable struct{ err error } 16 | 17 | func (v testVerifiable) Verify() error { 18 | return v.err 19 | } 20 | 21 | func TestAllNil(t *testing.T) { 22 | require.NoError(t, All( 23 | testVerifiable{}, 24 | testVerifiable{}, 25 | )) 26 | } 27 | 28 | func TestAllError(t *testing.T) { 29 | err := All( 30 | testVerifiable{}, 31 | testVerifiable{err: errTest}, 32 | ) 33 | require.ErrorIs(t, err, errTest) 34 | } 35 | -------------------------------------------------------------------------------- /vms/rpcchainvm/runtime/subprocess/non_linux_stopper.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | //go:build !linux 5 | // +build !linux 6 | 7 | package subprocess 8 | 9 | import ( 10 | "context" 11 | "os/exec" 12 | 13 | "go.uber.org/zap" 14 | 15 | "github.com/ava-labs/avalanchego/utils/logging" 16 | ) 17 | 18 | func NewCmd(path string, args ...string) *exec.Cmd { 19 | return exec.Command(path, args...) 20 | } 21 | 22 | func stop(_ context.Context, log logging.Logger, cmd *exec.Cmd) { 23 | err := cmd.Process.Kill() 24 | if err == nil { 25 | log.Debug("subprocess was killed") 26 | } else { 27 | log.Error("subprocess was killed", 28 | zap.Error(err), 29 | ) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /genesis/bootstrappers_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package genesis 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/stretchr/testify/require" 10 | 11 | "github.com/ava-labs/avalanchego/utils/constants" 12 | ) 13 | 14 | func TestSampleBootstrappers(t *testing.T) { 15 | require := require.New(t) 16 | 17 | for networkID, networkName := range constants.NetworkIDToNetworkName { 18 | length := 10 19 | bootstrappers := SampleBootstrappers(networkID, length) 20 | t.Logf("%s bootstrappers: %+v", networkName, bootstrappers) 21 | 22 | if networkID == constants.MainnetID || networkID == constants.FujiID { 23 | require.Len(bootstrappers, length) 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /utils/bloom/hasher.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package bloom 5 | 6 | import ( 7 | "crypto/sha256" 8 | "encoding/binary" 9 | ) 10 | 11 | func Add(f *Filter, key, salt []byte) { 12 | f.Add(Hash(key, salt)) 13 | } 14 | 15 | func Contains(c Checker, key, salt []byte) bool { 16 | return c.Contains(Hash(key, salt)) 17 | } 18 | 19 | type Checker interface { 20 | Contains(hash uint64) bool 21 | } 22 | 23 | func Hash(key, salt []byte) uint64 { 24 | hash := sha256.New() 25 | // sha256.Write never returns errors 26 | _, _ = hash.Write(key) 27 | _, _ = hash.Write(salt) 28 | 29 | output := make([]byte, 0, sha256.Size) 30 | return binary.BigEndian.Uint64(hash.Sum(output)) 31 | } 32 | -------------------------------------------------------------------------------- /vms/evm/metrics/metricstest/metrics.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package metricstest 5 | 6 | import ( 7 | "sync" 8 | "testing" 9 | 10 | "github.com/ava-labs/libevm/metrics" 11 | ) 12 | 13 | var metricsLock sync.Mutex 14 | 15 | // WithMetrics enables [metrics.Enabled] for the test and prevents any other 16 | // tests with metrics from running concurrently. 17 | // 18 | // [metrics.Enabled] is restored to its original value during testing cleanup. 19 | func WithMetrics(t testing.TB) { 20 | metricsLock.Lock() 21 | initialValue := metrics.Enabled 22 | metrics.Enabled = true 23 | t.Cleanup(func() { 24 | metrics.Enabled = initialValue 25 | metricsLock.Unlock() 26 | }) 27 | } 28 | -------------------------------------------------------------------------------- /vms/rpcchainvm/runtime/subprocess/stopper.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package subprocess 5 | 6 | import ( 7 | "context" 8 | "os/exec" 9 | "sync" 10 | 11 | "github.com/ava-labs/avalanchego/utils/logging" 12 | "github.com/ava-labs/avalanchego/vms/rpcchainvm/runtime" 13 | ) 14 | 15 | func NewStopper(logger logging.Logger, cmd *exec.Cmd) runtime.Stopper { 16 | return &stopper{ 17 | cmd: cmd, 18 | logger: logger, 19 | } 20 | } 21 | 22 | type stopper struct { 23 | once sync.Once 24 | cmd *exec.Cmd 25 | logger logging.Logger 26 | } 27 | 28 | func (s *stopper) Stop(ctx context.Context) { 29 | s.once.Do(func() { 30 | stop(ctx, s.logger, s.cmd) 31 | }) 32 | } 33 | -------------------------------------------------------------------------------- /proto/signer/signer.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package signer; 4 | 5 | option go_package = "github.com/ava-labs/avalanchego/proto/pb/signer"; 6 | 7 | service Signer { 8 | rpc PublicKey(PublicKeyRequest) returns (PublicKeyResponse) {} 9 | rpc Sign(SignRequest) returns (SignResponse) {} 10 | rpc SignProofOfPossession(SignProofOfPossessionRequest) returns (SignProofOfPossessionResponse) {} 11 | } 12 | 13 | message PublicKeyRequest {} 14 | message PublicKeyResponse { 15 | bytes public_key = 1; 16 | } 17 | message SignRequest { 18 | bytes message = 1; 19 | } 20 | message SignResponse { 21 | bytes signature = 1; 22 | } 23 | message SignProofOfPossessionRequest { 24 | bytes message = 1; 25 | } 26 | message SignProofOfPossessionResponse { 27 | bytes signature = 1; 28 | } 29 | -------------------------------------------------------------------------------- /snow/networking/sender/external_sender.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package sender 5 | 6 | import ( 7 | "github.com/ava-labs/avalanchego/ids" 8 | "github.com/ava-labs/avalanchego/message" 9 | "github.com/ava-labs/avalanchego/snow/engine/common" 10 | "github.com/ava-labs/avalanchego/subnets" 11 | "github.com/ava-labs/avalanchego/utils/set" 12 | ) 13 | 14 | // ExternalSender sends consensus messages to other validators 15 | // Right now this is implemented in the networking package 16 | type ExternalSender interface { 17 | Send( 18 | msg message.OutboundMessage, 19 | config common.SendConfig, 20 | subnetID ids.ID, 21 | allower subnets.Allower, 22 | ) set.Set[ids.NodeID] 23 | } 24 | -------------------------------------------------------------------------------- /vms/avm/config.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package avm 5 | 6 | import ( 7 | "encoding/json" 8 | 9 | "github.com/ava-labs/avalanchego/vms/avm/network" 10 | ) 11 | 12 | var DefaultConfig = Config{ 13 | Network: network.DefaultConfig, 14 | ChecksumsEnabled: false, 15 | } 16 | 17 | type Config struct { 18 | Network network.Config `json:"network"` 19 | ChecksumsEnabled bool `json:"checksums-enabled"` 20 | } 21 | 22 | func ParseConfig(configBytes []byte) (Config, error) { 23 | if len(configBytes) == 0 { 24 | return DefaultConfig, nil 25 | } 26 | 27 | config := DefaultConfig 28 | err := json.Unmarshal(configBytes, &config) 29 | return config, err 30 | } 31 | -------------------------------------------------------------------------------- /vms/example/xsvm/cmd/issue/status/status.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package status 5 | 6 | import ( 7 | "encoding/json" 8 | "fmt" 9 | "time" 10 | 11 | "github.com/ava-labs/avalanchego/ids" 12 | "github.com/ava-labs/avalanchego/vms/example/xsvm/tx" 13 | ) 14 | 15 | type TxIssuance struct { 16 | Tx *tx.Tx 17 | TxID ids.ID 18 | Nonce uint64 19 | StartTime time.Time 20 | } 21 | 22 | func (s *TxIssuance) String() string { 23 | txJSON, err := json.MarshalIndent(s.Tx, "", " ") 24 | if err != nil { 25 | return "failed to marshal transaction: " + err.Error() 26 | } 27 | return fmt.Sprintf("issued tx %s in %s\n%s\n", s.TxID, time.Since(s.StartTime), string(txJSON)) 28 | } 29 | -------------------------------------------------------------------------------- /.github/actions/run-monitored-tmpnet-cmd/output-metrics-url.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | 5 | # Timestamps are in seconds 6 | from_timestamp="$(date '+%s')" 7 | monitoring_period=900 # 15 minutes 8 | to_timestamp="$((from_timestamp + monitoring_period))" 9 | 10 | # Grafana expects microseconds, so pad timestamps with 3 zeros 11 | metrics_url="${GRAFANA_URL}&var-filter=gh_job_id%7C%3D%7C${GH_JOB_ID}&from=${from_timestamp}000&to=${to_timestamp}000" 12 | 13 | # Optionally ensure that the link displays metrics only for the shared 14 | # network rather than mixing it with the results for private networks. 15 | if [[ -n "${FILTER_BY_OWNER:-}" ]]; then 16 | metrics_url="${metrics_url}&var-filter=network_owner%7C%3D%7C${FILTER_BY_OWNER}" 17 | fi 18 | 19 | echo "${metrics_url}" 20 | -------------------------------------------------------------------------------- /utils/filesystem/io.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package filesystem 5 | 6 | import ( 7 | "io/fs" 8 | "os" 9 | ) 10 | 11 | var _ Reader = reader{} 12 | 13 | // Reader is an interface for reading the filesystem. 14 | type Reader interface { 15 | // ReadDir reads a given directory. 16 | // Returns the files in the directory. 17 | ReadDir(string) ([]fs.DirEntry, error) 18 | } 19 | 20 | type reader struct{} 21 | 22 | // NewReader returns an instance of Reader 23 | func NewReader() Reader { 24 | return reader{} 25 | } 26 | 27 | // This is just a wrapper around os.ReadDir to make testing easier. 28 | func (reader) ReadDir(dirname string) ([]fs.DirEntry, error) { 29 | return os.ReadDir(dirname) 30 | } 31 | -------------------------------------------------------------------------------- /utils/filesystem/mock_file.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package filesystem 5 | 6 | import "io/fs" 7 | 8 | var _ fs.DirEntry = MockFile{} 9 | 10 | // MockFile is an implementation of fs.File for unit testing. 11 | type MockFile struct { 12 | MockName string 13 | MockIsDir bool 14 | MockType fs.FileMode 15 | MockInfo fs.FileInfo 16 | MockInfoErr error 17 | } 18 | 19 | func (m MockFile) Name() string { 20 | return m.MockName 21 | } 22 | 23 | func (m MockFile) IsDir() bool { 24 | return m.MockIsDir 25 | } 26 | 27 | func (m MockFile) Type() fs.FileMode { 28 | return m.MockType 29 | } 30 | 31 | func (m MockFile) Info() (fs.FileInfo, error) { 32 | return m.MockInfo, m.MockInfoErr 33 | } 34 | -------------------------------------------------------------------------------- /vms/components/verify/verification.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package verify 5 | 6 | import "github.com/ava-labs/avalanchego/snow" 7 | 8 | type Verifiable interface { 9 | Verify() error 10 | } 11 | 12 | type State interface { 13 | snow.ContextInitializable 14 | Verifiable 15 | IsState 16 | } 17 | 18 | type IsState interface { 19 | isState() 20 | } 21 | 22 | type IsNotState interface { 23 | isState() error 24 | } 25 | 26 | // All returns nil if all the verifiables were verified with no errors 27 | func All(verifiables ...Verifiable) error { 28 | for _, verifiable := range verifiables { 29 | if err := verifiable.Verify(); err != nil { 30 | return err 31 | } 32 | } 33 | return nil 34 | } 35 | -------------------------------------------------------------------------------- /database/rpcdb/errors.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package rpcdb 5 | 6 | import ( 7 | "github.com/ava-labs/avalanchego/database" 8 | 9 | rpcdbpb "github.com/ava-labs/avalanchego/proto/pb/rpcdb" 10 | ) 11 | 12 | var ( 13 | ErrEnumToError = map[rpcdbpb.Error]error{ 14 | rpcdbpb.Error_ERROR_CLOSED: database.ErrClosed, 15 | rpcdbpb.Error_ERROR_NOT_FOUND: database.ErrNotFound, 16 | } 17 | ErrorToErrEnum = map[error]rpcdbpb.Error{ 18 | database.ErrClosed: rpcdbpb.Error_ERROR_CLOSED, 19 | database.ErrNotFound: rpcdbpb.Error_ERROR_NOT_FOUND, 20 | } 21 | ) 22 | 23 | func ErrorToRPCError(err error) error { 24 | if _, ok := ErrorToErrEnum[err]; ok { 25 | return nil 26 | } 27 | return err 28 | } 29 | -------------------------------------------------------------------------------- /scripts/start_kind_cluster.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | 5 | # --kubeconfig and --kubeconfig-context should be provided in the form --arg=value 6 | # to work with the simplistic mechanism enabling flag reuse. 7 | 8 | # Enable reuse of the arguments to ginkgo relevant to starting a cluster 9 | START_CLUSTER_ARGS=() 10 | for arg in "$@"; do 11 | if [[ "${arg}" =~ "--kubeconfig=" || "${arg}" =~ "--kubeconfig-context=" || "${arg}" =~ "--start-metrics-collector" || "${arg}" =~ "--start-logs-collector" ]]; then 12 | START_CLUSTER_ARGS+=("${arg}") 13 | fi 14 | done 15 | echo "Starting kind cluster with args: ${START_CLUSTER_ARGS[*]}" 16 | echo "To cleanup the cluster, run ./scripts/run_task.sh delete-kind-cluster" 17 | ./bin/tmpnetctl start-kind-cluster "${START_CLUSTER_ARGS[@]}" 18 | -------------------------------------------------------------------------------- /utils/crypto/bls/signer/localsigner/benchmark_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package localsigner 5 | 6 | import ( 7 | "strconv" 8 | "testing" 9 | 10 | "github.com/stretchr/testify/require" 11 | 12 | "github.com/ava-labs/avalanchego/utils" 13 | "github.com/ava-labs/avalanchego/utils/crypto/bls/blstest" 14 | ) 15 | 16 | func BenchmarkSign(b *testing.B) { 17 | signer := NewSigner(require.New(b)) 18 | for _, messageSize := range blstest.BenchmarkSizes { 19 | b.Run(strconv.Itoa(messageSize), func(b *testing.B) { 20 | message := utils.RandomBytes(messageSize) 21 | 22 | b.ResetTimer() 23 | 24 | for n := 0; n < b.N; n++ { 25 | _, _ = signer.Sign(message) 26 | } 27 | }) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /vms/proposervm/summary/build.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package summary 5 | 6 | import ( 7 | "fmt" 8 | 9 | "github.com/ava-labs/avalanchego/utils/hashing" 10 | ) 11 | 12 | func Build( 13 | forkHeight uint64, 14 | block []byte, 15 | coreSummary []byte, 16 | ) (StateSummary, error) { 17 | summary := stateSummary{ 18 | Height: forkHeight, 19 | Block: block, 20 | InnerSummary: coreSummary, 21 | } 22 | 23 | bytes, err := Codec.Marshal(CodecVersion, &summary) 24 | if err != nil { 25 | return nil, fmt.Errorf("cannot marshal proposer summary due to: %w", err) 26 | } 27 | 28 | summary.id = hashing.ComputeHash256Array(bytes) 29 | summary.bytes = bytes 30 | return &summary, nil 31 | } 32 | -------------------------------------------------------------------------------- /vms/platformvm/warp/payload/codec.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package payload 5 | 6 | import ( 7 | "errors" 8 | 9 | "github.com/ava-labs/avalanchego/codec" 10 | "github.com/ava-labs/avalanchego/codec/linearcodec" 11 | "github.com/ava-labs/avalanchego/utils/units" 12 | ) 13 | 14 | const ( 15 | CodecVersion = 0 16 | 17 | MaxMessageSize = 24 * units.KiB 18 | ) 19 | 20 | var Codec codec.Manager 21 | 22 | func init() { 23 | Codec = codec.NewManager(MaxMessageSize) 24 | lc := linearcodec.NewDefault() 25 | 26 | err := errors.Join( 27 | lc.RegisterType(&Hash{}), 28 | lc.RegisterType(&AddressedCall{}), 29 | Codec.RegisterCodec(CodecVersion, lc), 30 | ) 31 | if err != nil { 32 | panic(err) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "gomod" # See documentation for possible values 9 | directory: "/" # Location of package manifests 10 | schedule: 11 | interval: "daily" 12 | open-pull-requests-limit: 0 # Disable non-security version updates 13 | - package-ecosystem: github-actions 14 | directory: "/" 15 | schedule: 16 | interval: weekly 17 | open-pull-requests-limit: 0 # Disable non-security version updates 18 | -------------------------------------------------------------------------------- /flake.lock: -------------------------------------------------------------------------------- 1 | { 2 | "nodes": { 3 | "nixpkgs": { 4 | "locked": { 5 | "lastModified": 1752620740, 6 | "narHash": "sha256-f3pO+9lg66mV7IMmmIqG4PL3223TYMlnlw+pnpelbss=", 7 | "rev": "32a4e87942101f1c9f9865e04dc3ddb175f5f32e", 8 | "revCount": 806427, 9 | "type": "tarball", 10 | "url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.2505.806427%2Brev-32a4e87942101f1c9f9865e04dc3ddb175f5f32e/019816e8-f0d0-7f8f-866a-81065956761d/source.tar.gz" 11 | }, 12 | "original": { 13 | "type": "tarball", 14 | "url": "https://flakehub.com/f/NixOS/nixpkgs/0.2505.%2A.tar.gz" 15 | } 16 | }, 17 | "root": { 18 | "inputs": { 19 | "nixpkgs": "nixpkgs" 20 | } 21 | } 22 | }, 23 | "root": "root", 24 | "version": 7 25 | } 26 | -------------------------------------------------------------------------------- /proto/io/reader/reader.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package io.reader; 4 | 5 | option go_package = "github.com/ava-labs/avalanchego/proto/pb/io/reader"; 6 | 7 | // Reader is an io.Reader see: https://pkg.go.dev/io#Reader 8 | service Reader { 9 | rpc Read(ReadRequest) returns (ReadResponse); 10 | } 11 | 12 | message ReadRequest { 13 | // length is the request in bytes 14 | int32 length = 1; 15 | } 16 | 17 | message ReadResponse { 18 | // read is the payload in bytes 19 | bytes read = 1; 20 | // error is an error message 21 | Error error = 2; 22 | } 23 | 24 | message Error { 25 | ErrorCode error_code = 1; 26 | string message = 2; 27 | } 28 | 29 | // ErrorCode provides information for special sentinel error types 30 | enum ErrorCode { 31 | ERROR_CODE_UNSPECIFIED = 0; 32 | ERROR_CODE_EOF = 1; 33 | } 34 | -------------------------------------------------------------------------------- /vms/avm/txs/executor/backend.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package executor 5 | 6 | import ( 7 | "reflect" 8 | 9 | "github.com/ava-labs/avalanchego/codec" 10 | "github.com/ava-labs/avalanchego/ids" 11 | "github.com/ava-labs/avalanchego/snow" 12 | "github.com/ava-labs/avalanchego/vms/avm/config" 13 | "github.com/ava-labs/avalanchego/vms/avm/fxs" 14 | ) 15 | 16 | type Backend struct { 17 | Ctx *snow.Context 18 | Config *config.Config 19 | Fxs []*fxs.ParsedFx 20 | TypeToFxIndex map[reflect.Type]int 21 | Codec codec.Manager 22 | // Note: FeeAssetID may be different than ctx.AVAXAssetID if this AVM is 23 | // running in a subnet. 24 | FeeAssetID ids.ID 25 | Bootstrapped bool 26 | } 27 | -------------------------------------------------------------------------------- /vms/proposervm/block/codec.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package block 5 | 6 | import ( 7 | "errors" 8 | "math" 9 | 10 | "github.com/ava-labs/avalanchego/codec" 11 | "github.com/ava-labs/avalanchego/codec/linearcodec" 12 | ) 13 | 14 | const CodecVersion = 0 15 | 16 | var Codec codec.Manager 17 | 18 | func init() { 19 | lc := linearcodec.NewDefault() 20 | // The maximum block size is enforced by the p2p message size limit. 21 | // See: [constants.DefaultMaxMessageSize] 22 | Codec = codec.NewManager(math.MaxInt) 23 | 24 | err := errors.Join( 25 | lc.RegisterType(&statelessBlock{}), 26 | lc.RegisterType(&option{}), 27 | Codec.RegisterCodec(CodecVersion, lc), 28 | ) 29 | if err != nil { 30 | panic(err) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /database/common.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package database 5 | 6 | const ( 7 | // If, when a batch is reset, the cap(batch)/len(batch) > MaxExcessCapacityFactor, 8 | // the underlying array's capacity will be reduced by a factor of capacityReductionFactor. 9 | // Higher value for MaxExcessCapacityFactor --> less aggressive array downsizing --> less memory allocations 10 | // but more unnecessary data in the underlying array that can't be garbage collected. 11 | // Higher value for CapacityReductionFactor --> more aggressive array downsizing --> more memory allocations 12 | // but less unnecessary data in the underlying array that can't be garbage collected. 13 | MaxExcessCapacityFactor = 4 14 | CapacityReductionFactor = 2 15 | ) 16 | -------------------------------------------------------------------------------- /vms/example/xsvm/tx/transfer.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package tx 5 | 6 | import "github.com/ava-labs/avalanchego/ids" 7 | 8 | var _ Unsigned = (*Transfer)(nil) 9 | 10 | type Transfer struct { 11 | // ChainID provides cross chain replay protection 12 | ChainID ids.ID `serialize:"true" json:"chainID"` 13 | // Nonce provides internal chain replay protection 14 | Nonce uint64 `serialize:"true" json:"nonce"` 15 | MaxFee uint64 `serialize:"true" json:"maxFee"` 16 | AssetID ids.ID `serialize:"true" json:"assetID"` 17 | Amount uint64 `serialize:"true" json:"amount"` 18 | To ids.ShortID `serialize:"true" json:"to"` 19 | } 20 | 21 | func (t *Transfer) Visit(v Visitor) error { 22 | return v.Transfer(t) 23 | } 24 | -------------------------------------------------------------------------------- /vms/platformvm/warp/message/codec.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package message 5 | 6 | import ( 7 | "errors" 8 | "math" 9 | 10 | "github.com/ava-labs/avalanchego/codec" 11 | "github.com/ava-labs/avalanchego/codec/linearcodec" 12 | ) 13 | 14 | const CodecVersion = 0 15 | 16 | var Codec codec.Manager 17 | 18 | func init() { 19 | Codec = codec.NewManager(math.MaxInt) 20 | lc := linearcodec.NewDefault() 21 | 22 | err := errors.Join( 23 | lc.RegisterType(&SubnetToL1Conversion{}), 24 | lc.RegisterType(&RegisterL1Validator{}), 25 | lc.RegisterType(&L1ValidatorRegistration{}), 26 | lc.RegisterType(&L1ValidatorWeight{}), 27 | Codec.RegisterCodec(CodecVersion, lc), 28 | ) 29 | if err != nil { 30 | panic(err) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /snow/engine/avalanche/vertex/storage.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package vertex 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/ava-labs/avalanchego/ids" 10 | "github.com/ava-labs/avalanchego/snow/consensus/avalanche" 11 | ) 12 | 13 | // Storage defines the persistent storage that is required by the consensus 14 | // engine. 15 | type Storage interface { 16 | // Get a vertex by its hash from storage. 17 | GetVtx(ctx context.Context, vtxID ids.ID) (avalanche.Vertex, error) 18 | // Edge returns a list of accepted vertex IDs with no accepted children. 19 | Edge(ctx context.Context) (vtxIDs []ids.ID) 20 | // Returns "true" if accepted frontier ("Edge") is stop vertex. 21 | StopVertexAccepted(ctx context.Context) (bool, error) 22 | } 23 | -------------------------------------------------------------------------------- /connectproto/proposervm/service.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package proposervm; 4 | 5 | option go_package = "github.com/ava-labs/avalanchego/connectproto/pb/proposervm"; 6 | 7 | // ProposerVM service provides RPCs for querying ProposerVM state. 8 | service ProposerVM { 9 | // GetProposedHeight returns the P-Chain height that would be included in a 10 | // block if it were proposed right now. 11 | rpc GetProposedHeight(GetProposedHeightRequest) returns (GetProposedHeightReply); 12 | } 13 | 14 | // Request to get the current proposed block height. 15 | message GetProposedHeightRequest {} 16 | 17 | // Response containing the current proposed P-chain block height. 18 | message GetProposedHeightReply { 19 | // The P-chain height that would be included in a block if it were proposed 20 | // right now. 21 | uint64 height = 1; 22 | } 23 | -------------------------------------------------------------------------------- /tests/antithesis/avalanchego/gencomposeconfig/main.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package main 5 | 6 | import ( 7 | "os" 8 | 9 | "go.uber.org/zap" 10 | 11 | "github.com/ava-labs/avalanchego/tests" 12 | "github.com/ava-labs/avalanchego/tests/antithesis" 13 | "github.com/ava-labs/avalanchego/tests/fixture/tmpnet" 14 | ) 15 | 16 | const baseImageName = "antithesis-avalanchego" 17 | 18 | // Creates docker-compose.yml and its associated volumes in the target path. 19 | func main() { 20 | network := tmpnet.LocalNetworkOrPanic() 21 | if err := antithesis.GenerateComposeConfig(network, baseImageName); err != nil { 22 | tests.NewDefaultLogger("").Fatal("failed to generate compose config", 23 | zap.Error(err), 24 | ) 25 | os.Exit(1) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /api/metrics/service.md: -------------------------------------------------------------------------------- 1 | The Metrics API allows clients to get statistics about a node's health and performance. 2 | 3 | 4 | This API set is for a specific node, it is unavailable on the [public server](https://build.avax.network/docs/tooling/rpc-providers). 5 | 6 | 7 | ## Endpoint 8 | 9 | ``` 10 | /ext/metrics 11 | ``` 12 | 13 | ## Usage 14 | 15 | To get the node metrics: 16 | 17 | ```sh 18 | curl -X POST 127.0.0.1:9650/ext/metrics 19 | ``` 20 | 21 | ## Format 22 | 23 | This API produces Prometheus compatible metrics. See [here](https://prometheus.io/docs/instrumenting/exposition_formats) for information on Prometheus' formatting. 24 | 25 | [Here](https://build.avax.network/docs/nodes/maintain/monitoring) is a tutorial that shows how to set up Prometheus and Grafana to monitor AvalancheGo node using the Metrics API. 26 | -------------------------------------------------------------------------------- /utils/timer/stopped_timer.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package timer 5 | 6 | import "time" 7 | 8 | // StoppedTimer returns a stopped timer so that there is no entry on 9 | // the C channel (and there isn't one scheduled to be added). 10 | // 11 | // This means that after calling Reset there will be no events on the 12 | // channel until the timer fires (at which point there will be exactly 13 | // one event sent to the channel). 14 | // 15 | // It enables re-using the timer across loop iterations without 16 | // needing to have the first loop iteration perform any == nil checks 17 | // to initialize the first invocation. 18 | func StoppedTimer() *time.Timer { 19 | timer := time.NewTimer(0) 20 | if !timer.Stop() { 21 | <-timer.C 22 | } 23 | return timer 24 | } 25 | -------------------------------------------------------------------------------- /vms/components/avax/utxo.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package avax 5 | 6 | import ( 7 | "errors" 8 | 9 | "github.com/ava-labs/avalanchego/vms/components/verify" 10 | ) 11 | 12 | var ( 13 | errNilUTXO = errors.New("nil utxo is not valid") 14 | errEmptyUTXO = errors.New("empty utxo is not valid") 15 | 16 | _ verify.Verifiable = (*UTXO)(nil) 17 | ) 18 | 19 | type UTXO struct { 20 | UTXOID `serialize:"true"` 21 | Asset `serialize:"true"` 22 | 23 | Out verify.State `serialize:"true" json:"output"` 24 | } 25 | 26 | func (utxo *UTXO) Verify() error { 27 | switch { 28 | case utxo == nil: 29 | return errNilUTXO 30 | case utxo.Out == nil: 31 | return errEmptyUTXO 32 | default: 33 | return verify.All(&utxo.UTXOID, &utxo.Asset, utxo.Out) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /vms/proposervm/block/header.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package block 5 | 6 | import "github.com/ava-labs/avalanchego/ids" 7 | 8 | type Header interface { 9 | ChainID() ids.ID 10 | ParentID() ids.ID 11 | BodyID() ids.ID 12 | Bytes() []byte 13 | } 14 | 15 | type statelessHeader struct { 16 | Chain ids.ID `serialize:"true"` 17 | Parent ids.ID `serialize:"true"` 18 | Body ids.ID `serialize:"true"` 19 | 20 | bytes []byte 21 | } 22 | 23 | func (h *statelessHeader) ChainID() ids.ID { 24 | return h.Chain 25 | } 26 | 27 | func (h *statelessHeader) ParentID() ids.ID { 28 | return h.Parent 29 | } 30 | 31 | func (h *statelessHeader) BodyID() ids.ID { 32 | return h.Body 33 | } 34 | 35 | func (h *statelessHeader) Bytes() []byte { 36 | return h.bytes 37 | } 38 | -------------------------------------------------------------------------------- /cache/cache.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package cache 5 | 6 | // Cacher acts as a best effort key value store. 7 | type Cacher[K comparable, V any] interface { 8 | // Put inserts an element into the cache. If space is required, elements will 9 | // be evicted. 10 | Put(key K, value V) 11 | 12 | // Get returns the entry in the cache with the key specified, if no value 13 | // exists, false is returned. 14 | Get(key K) (V, bool) 15 | 16 | // Evict removes the specified entry from the cache 17 | Evict(key K) 18 | 19 | // Flush removes all entries from the cache 20 | Flush() 21 | 22 | // Returns the number of elements currently in the cache 23 | Len() int 24 | 25 | // Returns fraction of cache currently filled (0 --> 1) 26 | PortionFilled() float64 27 | } 28 | -------------------------------------------------------------------------------- /utils/formatting/int_format_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package formatting 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/stretchr/testify/require" 10 | ) 11 | 12 | func TestIntFormat(t *testing.T) { 13 | require := require.New(t) 14 | 15 | require.Equal("%01d", IntFormat(0)) 16 | require.Equal("%01d", IntFormat(9)) 17 | require.Equal("%02d", IntFormat(10)) 18 | require.Equal("%02d", IntFormat(99)) 19 | require.Equal("%03d", IntFormat(100)) 20 | require.Equal("%03d", IntFormat(999)) 21 | require.Equal("%04d", IntFormat(1000)) 22 | require.Equal("%04d", IntFormat(9999)) 23 | require.Equal("%05d", IntFormat(10000)) 24 | require.Equal("%05d", IntFormat(99999)) 25 | require.Equal("%06d", IntFormat(100000)) 26 | require.Equal("%06d", IntFormat(999999)) 27 | } 28 | -------------------------------------------------------------------------------- /vms/platformvm/txs/convert_subnet_to_l1_tx_test_simple.json: -------------------------------------------------------------------------------- 1 | { 2 | "networkID": 10, 3 | "blockchainID": "11111111111111111111111111111111LpoYY", 4 | "outputs": [], 5 | "inputs": [ 6 | { 7 | "txID": "2wiU5PnFTjTmoAXGZutHAsPF36qGGyLHYHj9G1Aucfmb3JFFGN", 8 | "outputIndex": 1, 9 | "assetID": "FvwEAhmxKfeiG8SnEvq42hc6whRyY3EFYAvebMqDNDGCgxN5Z", 10 | "fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ", 11 | "input": { 12 | "amount": 1000000, 13 | "signatureIndices": [ 14 | 5 15 | ] 16 | } 17 | } 18 | ], 19 | "memo": "0x", 20 | "subnetID": "SkB92YpWm4UpburLz9tEKZw2i67H3FF6YkjaU4BkFUDTG9Xm", 21 | "chainID": "NfebWJbJMmUpduqFCF8i1m5pstbVYLP1gGHbacrevXZMhpVMy", 22 | "address": "0x000000000000000000000000000000000000dead", 23 | "validators": [], 24 | "subnetAuthorization": { 25 | "signatureIndices": [ 26 | 3 27 | ] 28 | } 29 | } -------------------------------------------------------------------------------- /api/admin/key_value_reader.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package admin 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/ava-labs/avalanchego/database" 10 | ) 11 | 12 | var _ database.KeyValueReader = (*KeyValueReader)(nil) 13 | 14 | type KeyValueReader struct { 15 | client *Client 16 | } 17 | 18 | func NewKeyValueReader(client *Client) *KeyValueReader { 19 | return &KeyValueReader{ 20 | client: client, 21 | } 22 | } 23 | 24 | func (r *KeyValueReader) Has(key []byte) (bool, error) { 25 | _, err := r.client.DBGet(context.Background(), key) 26 | if err == database.ErrNotFound { 27 | return false, nil 28 | } 29 | return err == nil, err 30 | } 31 | 32 | func (r *KeyValueReader) Get(key []byte) ([]byte, error) { 33 | return r.client.DBGet(context.Background(), key) 34 | } 35 | -------------------------------------------------------------------------------- /chains/atomic/writer.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package atomic 5 | 6 | import "github.com/ava-labs/avalanchego/database" 7 | 8 | // WriteAll writes all of the batches to the underlying database of baseBatch. 9 | // Assumes all batches have the same underlying database. 10 | func WriteAll(baseBatch database.Batch, batches ...database.Batch) error { 11 | baseBatch = baseBatch.Inner() 12 | // Replay the inner batches onto [baseBatch] so that it includes all DB 13 | // operations as they would be applied to the base database. 14 | for _, batch := range batches { 15 | batch = batch.Inner() 16 | if err := batch.Replay(baseBatch); err != nil { 17 | return err 18 | } 19 | } 20 | // Write all of the combined operations in one atomic batch. 21 | return baseBatch.Write() 22 | } 23 | -------------------------------------------------------------------------------- /network/throttling/no_inbound_msg_throttler.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package throttling 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/ava-labs/avalanchego/ids" 10 | ) 11 | 12 | var _ InboundMsgThrottler = (*noInboundMsgThrottler)(nil) 13 | 14 | // Returns an InboundMsgThrottler where Acquire() always returns immediately. 15 | func NewNoInboundThrottler() InboundMsgThrottler { 16 | return &noInboundMsgThrottler{} 17 | } 18 | 19 | // [Acquire] always returns immediately. 20 | type noInboundMsgThrottler struct{} 21 | 22 | func (*noInboundMsgThrottler) Acquire(context.Context, uint64, ids.NodeID) ReleaseFunc { 23 | return noopRelease 24 | } 25 | 26 | func (*noInboundMsgThrottler) AddNode(ids.NodeID) {} 27 | 28 | func (*noInboundMsgThrottler) RemoveNode(ids.NodeID) {} 29 | -------------------------------------------------------------------------------- /utils/logging/config.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package logging 5 | 6 | type RotatingWriterConfig struct { 7 | MaxSize int `json:"maxSize"` // in megabytes 8 | MaxFiles int `json:"maxFiles"` 9 | MaxAge int `json:"maxAge"` // in days 10 | Directory string `json:"directory"` 11 | Compress bool `json:"compress"` 12 | } 13 | 14 | // Config defines the configuration of a logger 15 | type Config struct { 16 | RotatingWriterConfig 17 | DisableWriterDisplaying bool `json:"disableWriterDisplaying"` 18 | LogLevel Level `json:"logLevel"` 19 | DisplayLevel Level `json:"displayLevel"` 20 | LogFormat Format `json:"logFormat"` 21 | MsgPrefix string `json:"-"` 22 | LoggerName string `json:"-"` 23 | } 24 | -------------------------------------------------------------------------------- /utils/crypto/secp256k1/secp256k1_benchmark_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package secp256k1 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/stretchr/testify/require" 10 | 11 | "github.com/ava-labs/avalanchego/utils" 12 | "github.com/ava-labs/avalanchego/utils/hashing" 13 | ) 14 | 15 | func BenchmarkVerify(b *testing.B) { 16 | require := require.New(b) 17 | 18 | privateKey, err := NewPrivateKey() 19 | require.NoError(err) 20 | 21 | message := utils.RandomBytes(512) 22 | hash := hashing.ComputeHash256(message) 23 | 24 | publicKey := privateKey.PublicKey() 25 | signature, err := privateKey.SignHash(hash) 26 | require.NoError(err) 27 | 28 | b.ResetTimer() 29 | 30 | for n := 0; n < b.N; n++ { 31 | require.True(publicKey.VerifyHash(hash, signature)) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /snow/state.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package snow 5 | 6 | import ( 7 | "errors" 8 | 9 | "github.com/ava-labs/avalanchego/proto/pb/p2p" 10 | ) 11 | 12 | const ( 13 | Initializing State = iota 14 | StateSyncing 15 | Bootstrapping 16 | NormalOp 17 | ) 18 | 19 | var ErrUnknownState = errors.New("unknown state") 20 | 21 | type State uint8 22 | 23 | func (st State) String() string { 24 | switch st { 25 | case Initializing: 26 | return "Initializing state" 27 | case StateSyncing: 28 | return "State syncing state" 29 | case Bootstrapping: 30 | return "Bootstrapping state" 31 | case NormalOp: 32 | return "Normal operations state" 33 | default: 34 | return "Unknown state" 35 | } 36 | } 37 | 38 | type EngineState struct { 39 | Type p2p.EngineType 40 | State State 41 | } 42 | -------------------------------------------------------------------------------- /vms/platformvm/txs/subnet_validator_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package txs 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/stretchr/testify/require" 10 | 11 | "github.com/ava-labs/avalanchego/ids" 12 | "github.com/ava-labs/avalanchego/utils/constants" 13 | ) 14 | 15 | func TestSubnetValidatorVerifySubnetID(t *testing.T) { 16 | require := require.New(t) 17 | 18 | // Error path 19 | { 20 | vdr := &SubnetValidator{ 21 | Subnet: constants.PrimaryNetworkID, 22 | } 23 | 24 | err := vdr.Verify() 25 | require.ErrorIs(err, errBadSubnetID) 26 | } 27 | 28 | // Happy path 29 | { 30 | vdr := &SubnetValidator{ 31 | Subnet: ids.GenerateTestID(), 32 | Validator: Validator{ 33 | Wght: 1, 34 | }, 35 | } 36 | 37 | require.NoError(vdr.Verify()) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /vms/platformvm/warp/message/l1_validator_registration_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package message 5 | 6 | import ( 7 | "strconv" 8 | "testing" 9 | 10 | "github.com/stretchr/testify/require" 11 | 12 | "github.com/ava-labs/avalanchego/ids" 13 | ) 14 | 15 | func TestL1ValidatorRegistration(t *testing.T) { 16 | booleans := []bool{true, false} 17 | for _, registered := range booleans { 18 | t.Run(strconv.FormatBool(registered), func(t *testing.T) { 19 | require := require.New(t) 20 | 21 | msg, err := NewL1ValidatorRegistration( 22 | ids.GenerateTestID(), 23 | registered, 24 | ) 25 | require.NoError(err) 26 | 27 | parsed, err := ParseL1ValidatorRegistration(msg.Bytes()) 28 | require.NoError(err) 29 | require.Equal(msg, parsed) 30 | }) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /.github/actions/setup-go-for-project/action.yml: -------------------------------------------------------------------------------- 1 | # This action targets the project default version of setup-go. For 2 | # workers with old NodeJS incompatible with newer versions of 3 | # setup-go, try setup-go-for-project-v3. 4 | # 5 | # Since github actions do not support dynamically configuring the 6 | # versions in a uses statement (e.g. `actions/setup-go@${{ var }}`) it 7 | # is necessary to define an action per version rather than one action 8 | # that can be parameterized. 9 | # 10 | # Must be run after actions/checkout to ensure go.mod is available to 11 | # source the project's go version from. 12 | 13 | name: 'Install Go toolchain with project defaults' 14 | description: 'Install a go toolchain with project defaults' 15 | 16 | runs: 17 | using: composite 18 | steps: 19 | - name: Set up Go 20 | uses: actions/setup-go@v5 21 | with: 22 | go-version-file: go.mod 23 | -------------------------------------------------------------------------------- /utils/bloom/hasher_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package bloom 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/stretchr/testify/require" 10 | 11 | "github.com/ava-labs/avalanchego/ids" 12 | "github.com/ava-labs/avalanchego/utils/units" 13 | ) 14 | 15 | func TestCollisionResistance(t *testing.T) { 16 | require := require.New(t) 17 | 18 | f, err := New(8, 16*units.KiB) 19 | require.NoError(err) 20 | 21 | Add(f, []byte("hello world?"), []byte("so salty")) 22 | collision := Contains(f, []byte("hello world!"), []byte("so salty")) 23 | require.False(collision) 24 | } 25 | 26 | func BenchmarkHash(b *testing.B) { 27 | key := ids.GenerateTestID() 28 | salt := ids.GenerateTestID() 29 | 30 | b.ResetTimer() 31 | for i := 0; i < b.N; i++ { 32 | Hash(key[:], salt[:]) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /utils/sampler/weighted_without_replacement_benchmark_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package sampler 5 | 6 | import ( 7 | "fmt" 8 | "testing" 9 | 10 | "github.com/stretchr/testify/require" 11 | ) 12 | 13 | func BenchmarkWeightedWithoutReplacement(b *testing.B) { 14 | sizes := []int{ 15 | 1, 16 | 5, 17 | 25, 18 | 50, 19 | 75, 20 | 100, 21 | } 22 | for _, size := range sizes { 23 | b.Run(fmt.Sprintf("%d elements", size), func(b *testing.B) { 24 | require := require.New(b) 25 | s := NewWeightedWithoutReplacement() 26 | 27 | _, weights, err := CalcWeightedPoW(0, 100000) 28 | require.NoError(err) 29 | require.NoError(s.Initialize(weights)) 30 | 31 | b.ResetTimer() 32 | for i := 0; i < b.N; i++ { 33 | _, _ = s.Sample(size) 34 | } 35 | }) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /vms/proposervm/config.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package proposervm 5 | 6 | import ( 7 | "crypto" 8 | "time" 9 | 10 | "github.com/prometheus/client_golang/prometheus" 11 | 12 | "github.com/ava-labs/avalanchego/staking" 13 | "github.com/ava-labs/avalanchego/upgrade" 14 | ) 15 | 16 | type Config struct { 17 | Upgrades upgrade.Config 18 | 19 | // Configurable minimal delay among blocks issued consecutively 20 | MinBlkDelay time.Duration 21 | 22 | // Maximal number of block indexed. 23 | // Zero signals all blocks are indexed. 24 | NumHistoricalBlocks uint64 25 | 26 | // Block signer 27 | StakingLeafSigner crypto.Signer 28 | 29 | // Block certificate 30 | StakingCertLeaf *staking.Certificate 31 | 32 | // Registerer for prometheus metrics 33 | Registerer prometheus.Registerer 34 | } 35 | -------------------------------------------------------------------------------- /vms/rpcchainvm/gruntime/runtime_client.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package gruntime 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/ava-labs/avalanchego/vms/rpcchainvm/runtime" 10 | 11 | pb "github.com/ava-labs/avalanchego/proto/pb/vm/runtime" 12 | ) 13 | 14 | var _ runtime.Initializer = (*Client)(nil) 15 | 16 | // Client is a VM runtime initializer. 17 | type Client struct { 18 | client pb.RuntimeClient 19 | } 20 | 21 | func NewClient(client pb.RuntimeClient) *Client { 22 | return &Client{client: client} 23 | } 24 | 25 | func (c *Client) Initialize(ctx context.Context, protocolVersion uint, vmAddr string) error { 26 | _, err := c.client.Initialize(ctx, &pb.InitializeRequest{ 27 | ProtocolVersion: uint32(protocolVersion), 28 | Addr: vmAddr, 29 | }) 30 | return err 31 | } 32 | -------------------------------------------------------------------------------- /wallet/chain/x/builder/constants.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package builder 5 | 6 | import ( 7 | "github.com/ava-labs/avalanchego/vms/avm/block" 8 | "github.com/ava-labs/avalanchego/vms/avm/fxs" 9 | "github.com/ava-labs/avalanchego/vms/nftfx" 10 | "github.com/ava-labs/avalanchego/vms/propertyfx" 11 | "github.com/ava-labs/avalanchego/vms/secp256k1fx" 12 | ) 13 | 14 | const ( 15 | SECP256K1FxIndex = 0 16 | NFTFxIndex = 1 17 | PropertyFxIndex = 2 18 | ) 19 | 20 | // Parser to support serialization and deserialization 21 | var Parser block.Parser 22 | 23 | func init() { 24 | var err error 25 | Parser, err = block.NewParser( 26 | []fxs.Fx{ 27 | &secp256k1fx.Fx{}, 28 | &nftfx.Fx{}, 29 | &propertyfx.Fx{}, 30 | }, 31 | ) 32 | if err != nil { 33 | panic(err) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /vms/components/avax/utxo_handler.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package avax 5 | 6 | import "github.com/ava-labs/avalanchego/ids" 7 | 8 | // Removes the UTXOs consumed by [ins] from the UTXO set 9 | func Consume(utxoDB UTXODeleter, ins []*TransferableInput) { 10 | for _, input := range ins { 11 | utxoDB.DeleteUTXO(input.InputID()) 12 | } 13 | } 14 | 15 | // Adds the UTXOs created by [outs] to the UTXO set. 16 | // [txID] is the ID of the tx that created [outs]. 17 | func Produce( 18 | utxoDB UTXOAdder, 19 | txID ids.ID, 20 | outs []*TransferableOutput, 21 | ) { 22 | for index, out := range outs { 23 | utxoDB.AddUTXO(&UTXO{ 24 | UTXOID: UTXOID{ 25 | TxID: txID, 26 | OutputIndex: uint32(index), 27 | }, 28 | Asset: out.Asset, 29 | Out: out.Output(), 30 | }) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /snow/engine/avalanche/bootstrap/queue/parser_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package queue 5 | 6 | import ( 7 | "context" 8 | "errors" 9 | "testing" 10 | 11 | "github.com/stretchr/testify/require" 12 | ) 13 | 14 | var errParse = errors.New("unexpectedly called Parse") 15 | 16 | // TestParser is a test Parser 17 | type TestParser struct { 18 | T *testing.T 19 | 20 | CantParse bool 21 | 22 | ParseF func(context.Context, []byte) (Job, error) 23 | } 24 | 25 | func (p *TestParser) Default(cant bool) { 26 | p.CantParse = cant 27 | } 28 | 29 | func (p *TestParser) Parse(ctx context.Context, b []byte) (Job, error) { 30 | if p.ParseF != nil { 31 | return p.ParseF(ctx, b) 32 | } 33 | if p.CantParse && p.T != nil { 34 | require.FailNow(p.T, errParse.Error()) 35 | } 36 | return nil, errParse 37 | } 38 | -------------------------------------------------------------------------------- /vms/evm/metrics/prometheus/enabled_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package prometheus_test 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/ava-labs/libevm/metrics" 10 | "github.com/stretchr/testify/require" 11 | ) 12 | 13 | // This test assumes that there are no imported packages that might change the 14 | // default value of [metrics.Enabled]. It is therefore in package 15 | // `prometheus_test` in case any other tests modify the variable. If any imports 16 | // here or in the implementation do actually do so then this test may have false 17 | // negatives. 18 | func TestMetricsEnabledByDefault(t *testing.T) { 19 | require.True(t, metrics.Enabled, "libevm/metrics.Enabled") 20 | require.IsType(t, (*metrics.StandardCounter)(nil), metrics.NewCounter(), "metrics.NewCounter() returned wrong type") 21 | } 22 | -------------------------------------------------------------------------------- /vms/example/xsvm/tx/export.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package tx 5 | 6 | import "github.com/ava-labs/avalanchego/ids" 7 | 8 | var _ Unsigned = (*Export)(nil) 9 | 10 | type Export struct { 11 | // ChainID provides cross chain replay protection 12 | ChainID ids.ID `serialize:"true" json:"chainID"` 13 | // Nonce provides internal chain replay protection 14 | Nonce uint64 `serialize:"true" json:"nonce"` 15 | MaxFee uint64 `serialize:"true" json:"maxFee"` 16 | PeerChainID ids.ID `serialize:"true" json:"peerChainID"` 17 | IsReturn bool `serialize:"true" json:"isReturn"` 18 | Amount uint64 `serialize:"true" json:"amount"` 19 | To ids.ShortID `serialize:"true" json:"to"` 20 | } 21 | 22 | func (e *Export) Visit(v Visitor) error { 23 | return v.Export(e) 24 | } 25 | -------------------------------------------------------------------------------- /scripts/actionlint.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | 5 | AVALANCHE_PATH="$(cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd )" 6 | "${AVALANCHE_PATH}"/scripts/run_tool.sh actionlint "${@}" 7 | 8 | echo "Checking use of scripts/* in GitHub Actions workflows..." 9 | SCRIPT_USAGE= 10 | for file in "${AVALANCHE_PATH}"/.github/workflows/*.{yml,yaml}; do 11 | # Skip if no matches found (in case one of the extensions doesn't exist) 12 | [[ -f "$file" ]] || continue 13 | 14 | # Search for scripts/* except for scripts/run_task.sh 15 | MATCHES=$(grep -H -n -P "scripts/(?!run_task\.sh)" "$file" || true) 16 | if [[ -n "${MATCHES}" ]]; then 17 | echo "${MATCHES}" 18 | SCRIPT_USAGE=1 19 | fi 20 | done 21 | 22 | if [[ -n "${SCRIPT_USAGE}" ]]; then 23 | echo "Error: the lines listed above must be converted to use scripts/run_task.sh to ensure local reproducibility." 24 | exit 1 25 | fi 26 | -------------------------------------------------------------------------------- /snow/consensus/snowstorm/test_tx.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package snowstorm 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/ava-labs/avalanchego/ids" 10 | "github.com/ava-labs/avalanchego/snow/choices" 11 | "github.com/ava-labs/avalanchego/utils/set" 12 | ) 13 | 14 | var _ Tx = (*TestTx)(nil) 15 | 16 | // TestTx is a useful test tx 17 | type TestTx struct { 18 | choices.TestDecidable 19 | 20 | DependenciesV set.Set[ids.ID] 21 | DependenciesErrV error 22 | VerifyV error 23 | BytesV []byte 24 | } 25 | 26 | func (t *TestTx) MissingDependencies() (set.Set[ids.ID], error) { 27 | return t.DependenciesV, t.DependenciesErrV 28 | } 29 | 30 | func (t *TestTx) Verify(context.Context) error { 31 | return t.VerifyV 32 | } 33 | 34 | func (t *TestTx) Bytes() []byte { 35 | return t.BytesV 36 | } 37 | -------------------------------------------------------------------------------- /snow/engine/common/traced_state_syncer.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package common 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/ava-labs/avalanchego/trace" 10 | ) 11 | 12 | var _ StateSyncer = (*tracedStateSyncer)(nil) 13 | 14 | type tracedStateSyncer struct { 15 | Engine 16 | stateSyncer StateSyncer 17 | tracer trace.Tracer 18 | } 19 | 20 | func TraceStateSyncer(stateSyncer StateSyncer, tracer trace.Tracer) StateSyncer { 21 | return &tracedStateSyncer{ 22 | Engine: TraceEngine(stateSyncer, tracer), 23 | stateSyncer: stateSyncer, 24 | tracer: tracer, 25 | } 26 | } 27 | 28 | func (e *tracedStateSyncer) IsEnabled(ctx context.Context) (bool, error) { 29 | ctx, span := e.tracer.Start(ctx, "tracedStateSyncer.IsEnabled") 30 | defer span.End() 31 | 32 | return e.stateSyncer.IsEnabled(ctx) 33 | } 34 | -------------------------------------------------------------------------------- /utils/math/continuous_averager_benchmark_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package math 5 | 6 | import ( 7 | "fmt" 8 | "testing" 9 | "time" 10 | ) 11 | 12 | func BenchmarkAveragers(b *testing.B) { 13 | periods := []time.Duration{ 14 | time.Millisecond, 15 | time.Duration(0), 16 | -time.Millisecond, 17 | } 18 | for _, period := range periods { 19 | name := fmt.Sprintf("period=%s", period) 20 | b.Run(name, func(b *testing.B) { 21 | a := NewAverager(0, time.Second, time.Now()) 22 | AveragerBenchmark(b, a, period) 23 | }) 24 | } 25 | } 26 | 27 | func AveragerBenchmark(b *testing.B, a Averager, period time.Duration) { 28 | currentTime := time.Now() 29 | 30 | b.ResetTimer() 31 | for i := 0; i < b.N; i++ { 32 | currentTime = currentTime.Add(period) 33 | a.Observe(float64(i), currentTime) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /vms/proposervm/state/state_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package state 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/prometheus/client_golang/prometheus" 10 | "github.com/stretchr/testify/require" 11 | 12 | "github.com/ava-labs/avalanchego/database/memdb" 13 | "github.com/ava-labs/avalanchego/database/versiondb" 14 | ) 15 | 16 | func TestState(t *testing.T) { 17 | a := require.New(t) 18 | 19 | db := memdb.New() 20 | vdb := versiondb.New(db) 21 | s := New(vdb) 22 | 23 | testBlockState(a, s) 24 | testChainState(a, s) 25 | } 26 | 27 | func TestMeteredState(t *testing.T) { 28 | a := require.New(t) 29 | 30 | db := memdb.New() 31 | vdb := versiondb.New(db) 32 | s, err := NewMetered(vdb, "", prometheus.NewRegistry()) 33 | a.NoError(err) 34 | 35 | testBlockState(a, s) 36 | testChainState(a, s) 37 | } 38 | -------------------------------------------------------------------------------- /vms/tracedvm/build_block_with_context_vm.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package tracedvm 5 | 6 | import ( 7 | "context" 8 | 9 | "go.opentelemetry.io/otel/attribute" 10 | 11 | "github.com/ava-labs/avalanchego/snow/consensus/snowman" 12 | "github.com/ava-labs/avalanchego/snow/engine/snowman/block" 13 | 14 | oteltrace "go.opentelemetry.io/otel/trace" 15 | ) 16 | 17 | func (vm *blockVM) BuildBlockWithContext(ctx context.Context, blockCtx *block.Context) (snowman.Block, error) { 18 | if vm.buildBlockVM == nil { 19 | return vm.BuildBlock(ctx) 20 | } 21 | 22 | ctx, span := vm.tracer.Start(ctx, vm.buildBlockWithContextTag, oteltrace.WithAttributes( 23 | attribute.Int64("pChainHeight", int64(blockCtx.PChainHeight)), 24 | )) 25 | defer span.End() 26 | 27 | return vm.buildBlockVM.BuildBlockWithContext(ctx, blockCtx) 28 | } 29 | -------------------------------------------------------------------------------- /vms/example/xsvm/cmd/version/cmd.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package version 5 | 6 | import ( 7 | "fmt" 8 | 9 | "github.com/spf13/cobra" 10 | 11 | "github.com/ava-labs/avalanchego/utils/constants" 12 | "github.com/ava-labs/avalanchego/version" 13 | "github.com/ava-labs/avalanchego/vms/example/xsvm" 14 | ) 15 | 16 | const format = `%s: 17 | VMID: %s 18 | Version: %s 19 | Plugin Version: %d 20 | ` 21 | 22 | func Command() *cobra.Command { 23 | return &cobra.Command{ 24 | Use: "version", 25 | Short: "Prints out the version", 26 | RunE: versionFunc, 27 | } 28 | } 29 | 30 | func versionFunc(*cobra.Command, []string) error { 31 | fmt.Printf( 32 | format, 33 | constants.XSVMName, 34 | constants.XSVMID, 35 | xsvm.Version, 36 | version.RPCChainVMProtocol, 37 | ) 38 | return nil 39 | } 40 | -------------------------------------------------------------------------------- /tests/e2e/c/consume_gas.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package c 5 | 6 | const ( 7 | // consumeGasCompiledContract is the compiled bytecode of the contract 8 | // defined in consume_gas.sol. 9 | consumeGasCompiledContract = "6080604052348015600f57600080fd5b5060788061001e6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063c040622614602d575b600080fd5b60336035565b005b5b6001156040576036565b56fea264697066735822122070cfeeb0992270b4ff725a1264654534853d25ea6bb28c85d986beccfdbc997164736f6c63430008060033" 10 | // consumeGasABIJson is the ABI of the contract defined in consume_gas.sol. 11 | consumeGasABIJson = `[{"inputs":[],"name":"run","outputs":[],"stateMutability":"nonpayable","type":"function"}]` 12 | // consumeGasFunction is the name of the function to call to consume gas. 13 | consumeGasFunction = "run" 14 | ) 15 | -------------------------------------------------------------------------------- /vms/secp256k1fx/transfer_input.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package secp256k1fx 5 | 6 | import ( 7 | "errors" 8 | 9 | "github.com/ava-labs/avalanchego/snow" 10 | ) 11 | 12 | var ErrNoValueInput = errors.New("input has no value") 13 | 14 | type TransferInput struct { 15 | Amt uint64 `serialize:"true" json:"amount"` 16 | Input `serialize:"true"` 17 | } 18 | 19 | func (*TransferInput) InitCtx(*snow.Context) {} 20 | 21 | // Amount returns the quantity of the asset this input produces 22 | func (in *TransferInput) Amount() uint64 { 23 | return in.Amt 24 | } 25 | 26 | // Verify this input is syntactically valid 27 | func (in *TransferInput) Verify() error { 28 | switch { 29 | case in == nil: 30 | return ErrNilInput 31 | case in.Amt == 0: 32 | return ErrNoValueInput 33 | default: 34 | return in.Input.Verify() 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /network/handler_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package network 5 | 6 | import ( 7 | "github.com/ava-labs/avalanchego/ids" 8 | "github.com/ava-labs/avalanchego/snow/networking/router" 9 | "github.com/ava-labs/avalanchego/version" 10 | ) 11 | 12 | var _ router.ExternalHandler = (*testHandler)(nil) 13 | 14 | type testHandler struct { 15 | router.InboundHandler 16 | ConnectedF func(nodeID ids.NodeID, nodeVersion *version.Application, subnetID ids.ID) 17 | DisconnectedF func(nodeID ids.NodeID) 18 | } 19 | 20 | func (h *testHandler) Connected(id ids.NodeID, nodeVersion *version.Application, subnetID ids.ID) { 21 | if h.ConnectedF != nil { 22 | h.ConnectedF(id, nodeVersion, subnetID) 23 | } 24 | } 25 | 26 | func (h *testHandler) Disconnected(id ids.NodeID) { 27 | if h.DisconnectedF != nil { 28 | h.DisconnectedF(id) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /snow/consensus/snowball/binary_slush.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package snowball 5 | 6 | import "fmt" 7 | 8 | func newBinarySlush(choice int) binarySlush { 9 | return binarySlush{ 10 | preference: choice, 11 | } 12 | } 13 | 14 | // binarySlush is the implementation of a binary slush instance 15 | type binarySlush struct { 16 | // preference is the choice that last had a successful poll. Unless there 17 | // hasn't been a successful poll, in which case it is the initially provided 18 | // choice. 19 | preference int 20 | } 21 | 22 | func (sl *binarySlush) Preference() int { 23 | return sl.preference 24 | } 25 | 26 | func (sl *binarySlush) RecordSuccessfulPoll(choice int) { 27 | sl.preference = choice 28 | } 29 | 30 | func (sl *binarySlush) String() string { 31 | return fmt.Sprintf("SL(Preference = %d)", sl.preference) 32 | } 33 | --------------------------------------------------------------------------------