├── .dockerignore ├── .editorconfig ├── .gitignore ├── .golangci.yml ├── Dockerfile ├── LICENSE ├── README.md ├── api ├── admin │ ├── client.go │ ├── client_test.go │ ├── key_value_reader.go │ ├── service.go │ ├── service.md │ └── service_test.go ├── common_args_responses.go ├── health │ ├── README.md │ ├── checker.go │ ├── client.go │ ├── client_test.go │ ├── handler.go │ ├── health.go │ ├── health_test.go │ ├── metrics.go │ ├── result.go │ ├── service.go │ ├── service.md │ ├── service_test.go │ └── worker.go ├── info │ ├── client.go │ ├── client_test.go │ ├── service.go │ ├── service.md │ └── service_test.go ├── keystore │ ├── blockchain_keystore.go │ ├── client.go │ ├── codec.go │ ├── gkeystore │ │ ├── keystore_client.go │ │ └── keystore_server.go │ ├── keystore.go │ ├── service.go │ ├── service.md │ └── service_test.go ├── metrics │ ├── gatherer_test.go │ ├── multi_gatherer.go │ ├── multi_gatherer_test.go │ ├── optional_gatherer.go │ ├── optional_gatherer_test.go │ └── service.md ├── server │ ├── allowed_hosts.go │ ├── allowed_hosts_test.go │ ├── metrics.go │ ├── mock_server.go │ ├── router.go │ ├── router_test.go │ ├── server.go │ └── server_test.go └── traced_handler.go ├── app └── app.go ├── cache ├── cache.go ├── empty_cache.go ├── lru_cache.go ├── lru_cache_benchmark_test.go ├── lru_cache_test.go ├── lru_sized_cache.go ├── lru_sized_cache_test.go ├── metercacher │ ├── cache.go │ ├── cache_test.go │ └── metrics.go ├── test_cacher.go ├── unique_cache.go └── unique_cache_test.go ├── chains ├── atomic │ ├── README.md │ ├── codec.go │ ├── gsharedmemory │ │ ├── filtered_batch.go │ │ ├── shared_memory_client.go │ │ ├── shared_memory_server.go │ │ └── shared_memory_test.go │ ├── memory.go │ ├── memory_test.go │ ├── mock_shared_memory.go │ ├── prefixes.go │ ├── shared_memory.go │ ├── shared_memory_test.go │ ├── state.go │ ├── test_shared_memory.go │ └── writer.go ├── linearizable_vm.go ├── manager.go ├── registrant.go ├── subnets.go ├── subnets_test.go └── test_manager.go ├── codec ├── codec.go ├── general_codec.go ├── hierarchycodec │ ├── codec.go │ └── codec_test.go ├── linearcodec │ ├── codec.go │ └── codec_test.go ├── manager.go ├── mock_manager.go ├── reflectcodec │ ├── struct_fielder.go │ └── type_codec.go ├── registry.go └── test_codec.go ├── config ├── config.go ├── config.md ├── config_test.go ├── flags.go ├── keys.go └── viper.go ├── database ├── batch.go ├── benchmark_database.go ├── common.go ├── corruptabledb │ ├── db.go │ └── db_test.go ├── database.go ├── encdb │ ├── codec.go │ ├── db.go │ └── db_test.go ├── errors.go ├── helpers.go ├── helpers_test.go ├── iterator.go ├── leveldb │ ├── db.go │ ├── db_test.go │ └── metrics.go ├── linkeddb │ ├── codec.go │ ├── linkeddb.go │ └── linkeddb_test.go ├── memdb │ ├── db.go │ └── db_test.go ├── meterdb │ ├── db.go │ ├── db_test.go │ └── metrics.go ├── mock_batch.go ├── mock_iterator.go ├── pebble │ ├── batch.go │ ├── batch_test.go │ ├── db.go │ ├── db_test.go │ └── iterator.go ├── prefixdb │ ├── db.go │ └── db_test.go ├── rpcdb │ ├── db_client.go │ ├── db_server.go │ ├── db_test.go │ └── errors.go ├── test_database.go └── versiondb │ ├── db.go │ └── db_test.go ├── genesis ├── aliases.go ├── bootstrappers.go ├── bootstrappers.json ├── bootstrappers_test.go ├── checkpoints.go ├── checkpoints.json ├── config.go ├── config_test.go ├── generate │ ├── checkpoints │ │ └── main.go │ └── validators │ │ └── main.go ├── genesis.go ├── genesis_banana.go ├── genesis_banana.json ├── genesis_bluebyte.go ├── genesis_bluebyte.json ├── genesis_fusion.go ├── genesis_fusion.json ├── genesis_local.go ├── genesis_local.json ├── genesis_mainnet.go ├── genesis_mainnet.json ├── genesis_socotra.go ├── genesis_socotra.json ├── genesis_test.go ├── genesis_test.json ├── params.go ├── unparsed_config.go ├── validators.go └── validators.json ├── go.mod ├── go.sum ├── header.yml ├── ids ├── aliases.go ├── aliases_test.go ├── bits.go ├── bits_test.go ├── galiasreader │ ├── alias_reader_client.go │ ├── alias_reader_server.go │ └── alias_reader_test.go ├── id.go ├── id_test.go ├── node_id.go ├── node_id_test.go ├── request_id.go ├── short.go ├── test_aliases.go └── test_generator.go ├── indexer ├── client.go ├── client_test.go ├── codec.go ├── container.go ├── examples │ ├── p-chain │ │ └── main.go │ └── x-chain-blocks │ │ └── main.go ├── index.go ├── index_test.go ├── indexer.go ├── indexer_test.go ├── service.go └── service.md ├── main ├── default.pgo └── main.go ├── message ├── creator.go ├── fields.go ├── inbound_msg_builder.go ├── inbound_msg_builder_test.go ├── internal_msg_builder.go ├── messages.go ├── messages_benchmark_test.go ├── messages_test.go ├── mock_message.go ├── mock_outbound_message_builder.go ├── ops.go ├── outbound_msg_builder.go └── outbound_msg_builder_test.go ├── nat ├── nat.go ├── no_router.go ├── pmp.go └── upnp.go ├── network ├── README.md ├── certs_test.go ├── config.go ├── conn_test.go ├── dialer │ ├── dialer.go │ └── dialer_test.go ├── dialer_test.go ├── example_test.go ├── handler_test.go ├── ip_tracker.go ├── ip_tracker_test.go ├── listener_test.go ├── metrics.go ├── network.go ├── network_test.go ├── p2p │ ├── client.go │ ├── gossip │ │ ├── bloom.go │ │ ├── bloom_test.go │ │ ├── gossip.go │ │ ├── gossip_test.go │ │ ├── gossipable.go │ │ ├── handler.go │ │ ├── message.go │ │ └── test_gossip.go │ ├── handler.go │ ├── handler_test.go │ ├── network.go │ ├── network_test.go │ ├── node_sampler.go │ ├── peer_tracker.go │ ├── peer_tracker_test.go │ ├── router.go │ ├── throttler.go │ ├── throttler_handler.go │ ├── throttler_handler_test.go │ ├── throttler_test.go │ ├── validators.go │ └── validators_test.go ├── peer │ ├── config.go │ ├── example_test.go │ ├── info.go │ ├── ip.go │ ├── ip_signer.go │ ├── ip_signer_test.go │ ├── ip_test.go │ ├── message_queue.go │ ├── message_queue_test.go │ ├── metrics.go │ ├── msg_length.go │ ├── msg_length_test.go │ ├── network.go │ ├── peer.go │ ├── peer_test.go │ ├── set.go │ ├── set_test.go │ ├── test_network.go │ ├── test_peer.go │ ├── tls_config.go │ └── upgrader.go ├── test_cert_1.crt ├── test_cert_2.crt ├── test_cert_3.crt ├── test_key_1.key ├── test_key_2.key ├── test_key_3.key ├── test_network.go ├── throttling │ ├── bandwidth_throttler.go │ ├── bandwidth_throttler_test.go │ ├── common.go │ ├── dial_throttler.go │ ├── dial_throttler_test.go │ ├── inbound_conn_throttler.go │ ├── inbound_conn_throttler_test.go │ ├── inbound_conn_upgrade_throttler.go │ ├── inbound_conn_upgrade_throttler_test.go │ ├── inbound_msg_buffer_throttler.go │ ├── inbound_msg_buffer_throttler_test.go │ ├── inbound_msg_byte_throttler.go │ ├── inbound_msg_byte_throttler_test.go │ ├── inbound_msg_throttler.go │ ├── inbound_resource_throttler.go │ ├── inbound_resource_throttler_test.go │ ├── no_inbound_msg_throttler.go │ ├── outbound_msg_throttler.go │ ├── outbound_msg_throttler_test.go │ └── release_func.go ├── tracked_ip.go └── tracked_ip_test.go ├── node ├── beacon_manager.go ├── beacon_manager_test.go ├── config.go ├── insecure_validator_manager.go ├── node.go ├── overridden_manager.go └── overridden_manager_test.go ├── proto ├── Dockerfile.buf ├── README.md ├── aliasreader │ └── aliasreader.proto ├── appsender │ └── appsender.proto ├── buf.gen.yaml ├── buf.lock ├── buf.md ├── buf.yaml ├── http │ ├── http.proto │ └── responsewriter │ │ └── responsewriter.proto ├── io │ ├── reader │ │ └── reader.proto │ └── writer │ │ └── writer.proto ├── keystore │ └── keystore.proto ├── messenger │ └── messenger.proto ├── net │ └── conn │ │ └── conn.proto ├── p2p │ └── p2p.proto ├── pb │ ├── aliasreader │ │ ├── aliasreader.pb.go │ │ └── aliasreader_grpc.pb.go │ ├── appsender │ │ ├── appsender.pb.go │ │ └── appsender_grpc.pb.go │ ├── http │ │ ├── http.pb.go │ │ ├── http_grpc.pb.go │ │ └── responsewriter │ │ │ ├── responsewriter.pb.go │ │ │ └── responsewriter_grpc.pb.go │ ├── io │ │ ├── reader │ │ │ ├── reader.pb.go │ │ │ └── reader_grpc.pb.go │ │ └── writer │ │ │ ├── writer.pb.go │ │ │ └── writer_grpc.pb.go │ ├── keystore │ │ ├── keystore.pb.go │ │ └── keystore_grpc.pb.go │ ├── messenger │ │ ├── messenger.pb.go │ │ └── messenger_grpc.pb.go │ ├── net │ │ └── conn │ │ │ ├── conn.pb.go │ │ │ └── conn_grpc.pb.go │ ├── p2p │ │ └── p2p.pb.go │ ├── rpcdb │ │ ├── rpcdb.pb.go │ │ └── rpcdb_grpc.pb.go │ ├── sdk │ │ └── sdk.pb.go │ ├── sharedmemory │ │ ├── sharedmemory.pb.go │ │ └── sharedmemory_grpc.pb.go │ ├── sync │ │ ├── sync.pb.go │ │ └── sync_grpc.pb.go │ ├── validatorstate │ │ ├── validator_state.pb.go │ │ └── validator_state_grpc.pb.go │ ├── vm │ │ ├── runtime │ │ │ ├── runtime.pb.go │ │ │ └── runtime_grpc.pb.go │ │ ├── vm.pb.go │ │ └── vm_grpc.pb.go │ └── warp │ │ ├── message.pb.go │ │ └── message_grpc.pb.go ├── rpcdb │ └── rpcdb.proto ├── sdk │ └── sdk.proto ├── sharedmemory │ └── sharedmemory.proto ├── sync │ └── sync.proto ├── validatorstate │ └── validator_state.proto ├── vm │ ├── runtime │ │ └── runtime.proto │ └── vm.proto └── warp │ └── message.proto ├── pubsub ├── bloom │ ├── filter.go │ ├── filter_test.go │ └── map_filter.go ├── connection.go ├── connections.go ├── filter_param.go ├── filter_test.go ├── filterer.go ├── messages.go └── server.go ├── scripts ├── lint.sh ├── mock.gen.sh ├── mocks.mockgen.source.txt ├── mocks.mockgen.txt ├── protobuf_codegen.sh └── tbd │ ├── build.sh │ ├── build_avalanche.sh │ ├── build_fuzz.sh │ ├── build_image.sh │ ├── build_juneogo.sh │ ├── build_test.sh │ ├── build_xsvm.sh │ ├── constants.sh │ ├── shellcheck.sh │ └── tests.build_image.sh ├── snow ├── README.md ├── acceptor.go ├── choices │ ├── decidable.go │ ├── status.go │ ├── status_test.go │ └── test_decidable.go ├── consensus │ ├── avalanche │ │ ├── test_vertex.go │ │ └── vertex.go │ ├── snowball │ │ ├── binary_slush.go │ │ ├── binary_snowball.go │ │ ├── binary_snowball_test.go │ │ ├── binary_snowflake.go │ │ ├── binary_snowflake_test.go │ │ ├── consensus.go │ │ ├── consensus_performance_test.go │ │ ├── consensus_reversibility_test.go │ │ ├── consensus_test.go │ │ ├── factory.go │ │ ├── flat.go │ │ ├── flat_test.go │ │ ├── network_test.go │ │ ├── nnary_slush.go │ │ ├── nnary_snowball.go │ │ ├── nnary_snowball_test.go │ │ ├── nnary_snowflake.go │ │ ├── nnary_snowflake_test.go │ │ ├── parameters.go │ │ ├── parameters_test.go │ │ ├── tree.go │ │ ├── tree_test.go │ │ ├── unary_snowball.go │ │ ├── unary_snowball_test.go │ │ ├── unary_snowflake.go │ │ └── unary_snowflake_test.go │ ├── snowman │ │ ├── block.go │ │ ├── bootstrapper │ │ │ ├── majority.go │ │ │ ├── majority_test.go │ │ │ ├── minority.go │ │ │ ├── minority_test.go │ │ │ ├── noop.go │ │ │ ├── noop_test.go │ │ │ ├── poll.go │ │ │ ├── poll_test.go │ │ │ ├── requests.go │ │ │ ├── sampler.go │ │ │ └── sampler_test.go │ │ ├── consensus.go │ │ ├── consensus_test.go │ │ ├── factory.go │ │ ├── metrics.go │ │ ├── network_test.go │ │ ├── oracle_block.go │ │ ├── poll │ │ │ ├── early_term_no_traversal.go │ │ │ ├── early_term_no_traversal_test.go │ │ │ ├── interfaces.go │ │ │ ├── set.go │ │ │ └── set_test.go │ │ ├── snowman_block.go │ │ ├── snowmantest │ │ │ ├── block.go │ │ │ └── mock_block.go │ │ ├── topological.go │ │ ├── topological_test.go │ │ └── traced_consensus.go │ └── snowstorm │ │ ├── test_tx.go │ │ └── tx.go ├── context.go ├── engine │ ├── avalanche │ │ ├── bootstrap │ │ │ ├── bootstrapper.go │ │ │ ├── bootstrapper_test.go │ │ │ ├── config.go │ │ │ ├── metrics.go │ │ │ ├── queue │ │ │ │ ├── job.go │ │ │ │ ├── jobs.go │ │ │ │ ├── jobs_test.go │ │ │ │ ├── parser.go │ │ │ │ ├── state.go │ │ │ │ ├── test_job.go │ │ │ │ └── test_parser.go │ │ │ ├── tx_job.go │ │ │ └── vertex_job.go │ │ ├── engine.go │ │ ├── getter │ │ │ └── getter.go │ │ ├── state │ │ │ ├── prefixed_state.go │ │ │ ├── serializer.go │ │ │ ├── state.go │ │ │ ├── unique_vertex.go │ │ │ └── unique_vertex_test.go │ │ └── vertex │ │ │ ├── builder.go │ │ │ ├── builder_test.go │ │ │ ├── codec.go │ │ │ ├── manager.go │ │ │ ├── mock_vm.go │ │ │ ├── parser.go │ │ │ ├── parser_test.go │ │ │ ├── stateless_vertex.go │ │ │ ├── stateless_vertex_test.go │ │ │ ├── storage.go │ │ │ ├── test_builder.go │ │ │ ├── test_manager.go │ │ │ ├── test_parser.go │ │ │ ├── test_storage.go │ │ │ ├── test_vm.go │ │ │ └── vm.go │ ├── common │ │ ├── appsender │ │ │ ├── appsender_client.go │ │ │ └── appsender_server.go │ │ ├── bootstrap_tracker.go │ │ ├── bootstrapable.go │ │ ├── engine.go │ │ ├── error.go │ │ ├── error_test.go │ │ ├── fx.go │ │ ├── halter.go │ │ ├── message.go │ │ ├── mock_sender.go │ │ ├── no_ops_handlers.go │ │ ├── request.go │ │ ├── request_test.go │ │ ├── sender.go │ │ ├── state_syncer.go │ │ ├── test_bootstrap_tracker.go │ │ ├── test_bootstrapper.go │ │ ├── test_engine.go │ │ ├── test_sender.go │ │ ├── test_timer.go │ │ ├── test_vm.go │ │ ├── timer.go │ │ ├── traced_bootstrapable_engine.go │ │ ├── traced_engine.go │ │ ├── traced_state_syncer.go │ │ ├── tracker │ │ │ ├── accepted.go │ │ │ ├── accepted_test.go │ │ │ ├── peers.go │ │ │ ├── peers_test.go │ │ │ └── startup.go │ │ └── vm.go │ └── snowman │ │ ├── ancestor │ │ ├── tree.go │ │ └── tree_test.go │ │ ├── block │ │ ├── README.md │ │ ├── batched_vm.go │ │ ├── batched_vm_test.go │ │ ├── block_context_vm.go │ │ ├── mock_build_block_with_context_vm.go │ │ ├── mock_chain_vm.go │ │ ├── mock_state_syncable_vm.go │ │ ├── mock_with_verify_context.go │ │ ├── state_summary.go │ │ ├── state_sync_mode.go │ │ ├── state_syncable_vm.go │ │ ├── test_batched_vm.go │ │ ├── test_state_summary.go │ │ ├── test_state_syncable_vm.go │ │ ├── test_vm.go │ │ └── vm.go │ │ ├── bootstrap │ │ ├── acceptor.go │ │ ├── bootstrapper.go │ │ ├── bootstrapper_test.go │ │ ├── config.go │ │ ├── interval │ │ │ ├── blocks.go │ │ │ ├── blocks_test.go │ │ │ ├── interval.go │ │ │ ├── interval_test.go │ │ │ ├── state.go │ │ │ ├── tree.go │ │ │ └── tree_test.go │ │ ├── metrics.go │ │ ├── storage.go │ │ └── storage_test.go │ │ ├── config.go │ │ ├── config_test.go │ │ ├── getter │ │ ├── getter.go │ │ └── getter_test.go │ │ ├── issuer.go │ │ ├── memory_block.go │ │ ├── metrics.go │ │ ├── syncer │ │ ├── config.go │ │ ├── state_syncer.go │ │ ├── state_syncer_test.go │ │ └── utils_test.go │ │ ├── transitive.go │ │ ├── transitive_test.go │ │ └── voter.go ├── event │ ├── blockable.go │ ├── blocker.go │ └── blocker_test.go ├── networking │ ├── benchlist │ │ ├── benchable.go │ │ ├── benchlist.go │ │ ├── benchlist_test.go │ │ ├── manager.go │ │ ├── metrics.go │ │ └── test_benchable.go │ ├── handler │ │ ├── engine.go │ │ ├── engine_test.go │ │ ├── handler.go │ │ ├── handler_test.go │ │ ├── health.go │ │ ├── health_test.go │ │ ├── message_queue.go │ │ ├── message_queue_metrics.go │ │ ├── message_queue_test.go │ │ ├── metrics.go │ │ ├── mock_handler.go │ │ └── parser.go │ ├── router │ │ ├── chain_router.go │ │ ├── chain_router_metrics.go │ │ ├── chain_router_test.go │ │ ├── health.go │ │ ├── inbound_handler.go │ │ ├── main_test.go │ │ ├── mock_router.go │ │ ├── router.go │ │ └── traced_router.go │ ├── sender │ │ ├── external_sender.go │ │ ├── mock_external_sender.go │ │ ├── sender.go │ │ ├── sender_test.go │ │ ├── test_external_sender.go │ │ └── traced_sender.go │ ├── timeout │ │ ├── main_test.go │ │ ├── manager.go │ │ ├── manager_test.go │ │ ├── metrics.go │ │ └── mock_manager.go │ └── tracker │ │ ├── mock_resource_tracker.go │ │ ├── mock_targeter.go │ │ ├── resource_tracker.go │ │ ├── resource_tracker_test.go │ │ ├── targeter.go │ │ └── targeter_test.go ├── snowtest │ └── snowtest.go ├── state.go ├── uptime │ ├── locked_calculator.go │ ├── locked_calculator_test.go │ ├── manager.go │ ├── manager_test.go │ ├── mock_calculator.go │ ├── no_op_calculator.go │ ├── state.go │ └── test_state.go └── validators │ ├── connector.go │ ├── gvalidators │ ├── validator_state_client.go │ ├── validator_state_server.go │ └── validator_state_test.go │ ├── logger.go │ ├── manager.go │ ├── manager_test.go │ ├── mock_state.go │ ├── mock_supernet_connector.go │ ├── set.go │ ├── set_test.go │ ├── state.go │ ├── subnet_connector.go │ ├── test_state.go │ ├── traced_state.go │ ├── unhandled_subnet_connector.go │ └── validator.go ├── staking ├── asn1.go ├── certificate.go ├── large_rsa_key.cert ├── local │ ├── README.md │ ├── signer1.key │ ├── signer2.key │ ├── signer3.key │ ├── signer4.key │ ├── signer5.key │ ├── staker1.crt │ ├── staker1.key │ ├── staker2.crt │ ├── staker2.key │ ├── staker3.crt │ ├── staker3.key │ ├── staker4.crt │ ├── staker4.key │ ├── staker5.crt │ └── staker5.key ├── parse.go ├── parse_test.go ├── tls.go ├── tls_test.go └── verify.go ├── supernets ├── config.go ├── config.md ├── config_test.go ├── no_op_allower.go ├── subnet.go └── subnet_test.go ├── trace ├── exporter.go ├── exporter_type.go ├── noop.go └── tracer.go ├── utils ├── atomic.go ├── atomic_test.go ├── bag │ ├── bag.go │ ├── bag_benchmark_test.go │ ├── bag_test.go │ ├── unique_bag.go │ └── unique_bag_test.go ├── beacon │ ├── beacon.go │ ├── set.go │ └── set_test.go ├── bimap │ ├── bimap.go │ └── bimap_test.go ├── bloom │ ├── filter.go │ ├── filter_test.go │ ├── hasher.go │ ├── hasher_test.go │ ├── metrics.go │ ├── optimal.go │ ├── optimal_test.go │ ├── read_filter.go │ └── read_filter_test.go ├── buffer │ ├── bounded_nonblocking_queue.go │ ├── bounded_nonblocking_queue_test.go │ ├── unbounded_blocking_deque.go │ ├── unbounded_blocking_deque_test.go │ ├── unbounded_deque.go │ └── unbounded_deque_test.go ├── bytes.go ├── bytes_test.go ├── cb58 │ ├── cb58.go │ └── cb58_test.go ├── compression │ ├── compressor.go │ ├── compressor_test.go │ ├── no_compressor.go │ ├── no_compressor_test.go │ ├── type.go │ ├── type_test.go │ ├── zstd_compressor.go │ └── zstd_zip_bomb.bin ├── constants │ ├── acps.go │ ├── aliases.go │ ├── application.go │ ├── memory.go │ ├── network_ids.go │ ├── network_ids_test.go │ ├── networking.go │ └── vm_ids.go ├── crypto │ ├── bls │ │ ├── bls_benchmark_test.go │ │ ├── bls_test.go │ │ ├── public.go │ │ ├── public_test.go │ │ ├── secret.go │ │ ├── secret_test.go │ │ ├── signature.go │ │ └── signature_test.go │ ├── keychain │ │ ├── keychain.go │ │ ├── keychain_test.go │ │ ├── ledger.go │ │ └── mock_ledger.go │ ├── ledger │ │ ├── ledger.go │ │ └── ledger_test.go │ └── secp256k1 │ │ ├── rfc6979_test.go │ │ ├── secp256k1.go │ │ ├── secp256k1_benchmark_test.go │ │ ├── secp256k1_test.go │ │ └── test_keys.go ├── dynamicip │ ├── ifconfig_resolver.go │ ├── no_updater.go │ ├── opendns_resolver.go │ ├── resolver.go │ ├── resolver_test.go │ ├── updater.go │ └── updater_test.go ├── error.go ├── filesystem │ ├── io.go │ ├── mock_file.go │ ├── mock_io.go │ ├── rename.go │ └── rename_test.go ├── formatting │ ├── address │ │ ├── address.go │ │ └── converter.go │ ├── encoding.go │ ├── encoding_benchmark_test.go │ ├── encoding_test.go │ ├── int_format.go │ ├── int_format_test.go │ └── prefixed_stringer.go ├── hashing │ ├── consistent │ │ ├── hashable.go │ │ ├── ring.go │ │ └── ring_test.go │ ├── hasher.go │ ├── hashing.go │ └── mock_hasher.go ├── heap │ ├── map.go │ ├── map_test.go │ ├── queue.go │ ├── queue_test.go │ ├── set.go │ └── set_test.go ├── ips │ ├── claimed_ip_port.go │ ├── dynamic_ip_port.go │ ├── ip_port.go │ ├── ip_test.go │ ├── lookup.go │ └── lookup_test.go ├── json │ ├── codec.go │ ├── float32.go │ ├── float32_test.go │ ├── float64.go │ ├── uint16.go │ ├── uint32.go │ ├── uint64.go │ └── uint8.go ├── linked │ ├── hashmap.go │ ├── hashmap_test.go │ ├── list.go │ └── list_test.go ├── logging │ ├── color.go │ ├── config.go │ ├── factory.go │ ├── format.go │ ├── level.go │ ├── log.go │ ├── log_test.go │ ├── logger.go │ ├── sanitize.go │ └── test_log.go ├── math │ ├── averager.go │ ├── averager_heap.go │ ├── averager_heap_test.go │ ├── continuous_averager.go │ ├── continuous_averager_benchmark_test.go │ ├── continuous_averager_test.go │ ├── meter │ │ ├── continuous_meter.go │ │ ├── factory.go │ │ ├── meter.go │ │ ├── meter_benchmark_test.go │ │ └── meter_test.go │ ├── safe_math.go │ ├── safe_math_test.go │ └── sync_averager.go ├── maybe │ ├── maybe.go │ └── maybe_test.go ├── metric │ ├── api_interceptor.go │ ├── averager.go │ ├── namespace.go │ └── namespace_test.go ├── password │ ├── hash.go │ ├── hash_test.go │ ├── password.go │ └── password_test.go ├── perms │ ├── chmod.go │ ├── create.go │ ├── perms.go │ └── write_file.go ├── profiler │ ├── continuous.go │ ├── profiler.go │ └── profiler_test.go ├── resource │ ├── metrics.go │ ├── mock_user.go │ ├── no_usage.go │ ├── usage.go │ └── usage_test.go ├── rpc │ ├── json.go │ ├── options.go │ └── requester.go ├── sampler │ ├── rand.go │ ├── rand_test.go │ ├── uniform.go │ ├── uniform_benchmark_test.go │ ├── uniform_best.go │ ├── uniform_replacer.go │ ├── uniform_resample.go │ ├── uniform_test.go │ ├── weighted.go │ ├── weighted_array.go │ ├── weighted_array_test.go │ ├── weighted_benchmark_test.go │ ├── weighted_best.go │ ├── weighted_heap.go │ ├── weighted_heap_test.go │ ├── weighted_linear.go │ ├── weighted_linear_test.go │ ├── weighted_test.go │ ├── weighted_uniform.go │ ├── weighted_without_replacement.go │ ├── weighted_without_replacement_benchmark_test.go │ ├── weighted_without_replacement_generic.go │ └── weighted_without_replacement_test.go ├── set │ ├── bits.go │ ├── bits_64.go │ ├── bits_64_test.go │ ├── bits_test.go │ ├── sampleable_set.go │ ├── sampleable_set_test.go │ ├── set.go │ ├── set_benchmark_test.go │ └── set_test.go ├── setmap │ ├── setmap.go │ └── setmap_test.go ├── sorting.go ├── sorting_test.go ├── stacktrace.go ├── storage │ ├── storage_common.go │ ├── storage_unix.go │ └── storage_windows.go ├── timer │ ├── adaptive_timeout_manager.go │ ├── adaptive_timeout_manager_test.go │ ├── eta.go │ ├── meter.go │ ├── mockable │ │ ├── clock.go │ │ └── clock_test.go │ ├── timer.go │ └── timer_test.go ├── ulimit │ ├── ulimit_bsd.go │ ├── ulimit_darwin.go │ ├── ulimit_unix.go │ └── ulimit_windows.go ├── units │ ├── avax.go │ └── bytes.go ├── window │ ├── window.go │ └── window_test.go ├── wrappers │ ├── closers.go │ ├── errors.go │ ├── packing.go │ └── packing_test.go └── zero.go ├── version ├── application.go ├── application_test.go ├── compatibility.go ├── compatibility.json ├── compatibility_test.go ├── constants.go ├── constants_test.go ├── parser.go ├── parser_test.go ├── string.go ├── version.go └── version_test.go ├── vms ├── README.md ├── avm │ ├── block │ │ ├── block.go │ │ ├── block_test.go │ │ ├── builder │ │ │ ├── builder.go │ │ │ └── builder_test.go │ │ ├── executor │ │ │ ├── block.go │ │ │ ├── block_test.go │ │ │ ├── manager.go │ │ │ ├── manager_test.go │ │ │ └── mock_manager.go │ │ ├── mock_block.go │ │ ├── parser.go │ │ └── standard_block.go │ ├── client.go │ ├── client_test.go │ ├── config.go │ ├── config.md │ ├── config │ │ └── config.go │ ├── config_test.go │ ├── environment_test.go │ ├── factory.go │ ├── fx_test.go │ ├── fxs │ │ └── fx.go │ ├── genesis.go │ ├── genesis_test.go │ ├── health.go │ ├── index_test.go │ ├── metrics │ │ ├── metrics.go │ │ ├── mock_metrics.go │ │ └── tx_metrics.go │ ├── network │ │ ├── atomic.go │ │ ├── config.go │ │ ├── gossip.go │ │ ├── gossip_test.go │ │ ├── network.go │ │ ├── network_test.go │ │ └── tx_verifier.go │ ├── pubsub_filterer.go │ ├── pubsub_filterer_test.go │ ├── service.go │ ├── service.md │ ├── service_test.go │ ├── state │ │ ├── diff.go │ │ ├── mock_state.go │ │ ├── state.go │ │ ├── state_test.go │ │ └── versions.go │ ├── state_test.go │ ├── static_service.go │ ├── tx.go │ ├── tx_init.go │ ├── txs │ │ ├── base_tx.go │ │ ├── base_tx_test.go │ │ ├── codec.go │ │ ├── create_asset_tx.go │ │ ├── create_asset_tx_test.go │ │ ├── executor │ │ │ ├── backend.go │ │ │ ├── executor.go │ │ │ ├── executor_test.go │ │ │ ├── semantic_verifier.go │ │ │ ├── semantic_verifier_test.go │ │ │ ├── syntactic_verifier.go │ │ │ └── syntactic_verifier_test.go │ │ ├── export_tx.go │ │ ├── export_tx_test.go │ │ ├── import_tx.go │ │ ├── import_tx_test.go │ │ ├── initial_state.go │ │ ├── initial_state_test.go │ │ ├── mempool │ │ │ ├── mempool.go │ │ │ ├── mempool_test.go │ │ │ └── mock_mempool.go │ │ ├── mock_unsigned_tx.go │ │ ├── operation.go │ │ ├── operation_test.go │ │ ├── operation_tx.go │ │ ├── parser.go │ │ ├── tx.go │ │ └── visitor.go │ ├── utxo │ │ └── spender.go │ ├── vm.go │ ├── vm_benchmark_test.go │ ├── vm_regression_test.go │ ├── vm_test.go │ ├── wallet_client.go │ ├── wallet_service.go │ └── wallet_service_test.go ├── components │ ├── avax │ │ ├── addresses.go │ │ ├── asset.go │ │ ├── asset_test.go │ │ ├── atomic_utxos.go │ │ ├── base_tx.go │ │ ├── flow_checker.go │ │ ├── metadata.go │ │ ├── metadata_test.go │ │ ├── mock_transferable_in.go │ │ ├── mock_transferable_out.go │ │ ├── state.go │ │ ├── test_verifiable.go │ │ ├── transferables.go │ │ ├── transferables_test.go │ │ ├── utxo.go │ │ ├── utxo_fetching.go │ │ ├── utxo_fetching_test.go │ │ ├── utxo_handler.go │ │ ├── utxo_id.go │ │ ├── utxo_id_test.go │ │ ├── utxo_state.go │ │ ├── utxo_state_test.go │ │ └── utxo_test.go │ ├── chain │ │ ├── block.go │ │ ├── state.go │ │ └── state_test.go │ ├── index │ │ ├── index.go │ │ └── metrics.go │ ├── keystore │ │ ├── codec.go │ │ ├── user.go │ │ └── user_test.go │ └── verify │ │ ├── mock_verifiable.go │ │ ├── subnet.go │ │ ├── subnet_test.go │ │ ├── verification.go │ │ └── verification_test.go ├── example │ └── xsvm │ │ ├── README.md │ │ ├── api │ │ ├── client.go │ │ └── server.go │ │ ├── block │ │ ├── block.go │ │ └── codec.go │ │ ├── builder │ │ └── builder.go │ │ ├── chain │ │ ├── block.go │ │ └── chain.go │ │ ├── cmd │ │ ├── account │ │ │ ├── cmd.go │ │ │ └── flags.go │ │ ├── chain │ │ │ ├── cmd.go │ │ │ ├── create │ │ │ │ ├── cmd.go │ │ │ │ └── flags.go │ │ │ └── genesis │ │ │ │ ├── cmd.go │ │ │ │ └── flags.go │ │ ├── issue │ │ │ ├── cmd.go │ │ │ ├── export │ │ │ │ ├── cmd.go │ │ │ │ └── flags.go │ │ │ ├── importtx │ │ │ │ ├── cmd.go │ │ │ │ └── flags.go │ │ │ ├── status │ │ │ │ └── status.go │ │ │ └── transfer │ │ │ │ ├── cmd.go │ │ │ │ └── flags.go │ │ ├── run │ │ │ └── cmd.go │ │ ├── version │ │ │ └── cmd.go │ │ └── xsvm │ │ │ └── main.go │ │ ├── constants.go │ │ ├── execute │ │ ├── block.go │ │ ├── expects_context.go │ │ ├── genesis.go │ │ └── tx.go │ │ ├── factory.go │ │ ├── genesis │ │ ├── codec.go │ │ ├── genesis.go │ │ └── genesis_test.go │ │ ├── state │ │ ├── keys.go │ │ └── storage.go │ │ ├── tx │ │ ├── codec.go │ │ ├── export.go │ │ ├── import.go │ │ ├── payload.go │ │ ├── transfer.go │ │ ├── tx.go │ │ ├── unsigned.go │ │ └── visitor.go │ │ └── vm.go ├── fx │ └── factory.go ├── manager.go ├── metervm │ ├── batched_vm.go │ ├── block.go │ ├── block_metrics.go │ ├── block_vm.go │ ├── build_block_with_context_vm.go │ ├── metrics.go │ ├── state_syncable_vm.go │ ├── vertex_metrics.go │ └── vertex_vm.go ├── mock_manager.go ├── nftfx │ ├── credential.go │ ├── credential_test.go │ ├── factory.go │ ├── factory_test.go │ ├── fx.go │ ├── fx_test.go │ ├── mint_operation.go │ ├── mint_operation_test.go │ ├── mint_output.go │ ├── mint_output_test.go │ ├── transfer_operation.go │ ├── transfer_operation_test.go │ ├── transfer_output.go │ └── transfer_output_test.go ├── platformvm │ ├── api │ │ ├── static_service.go │ │ └── static_service_test.go │ ├── block │ │ ├── abort_block.go │ │ ├── abort_block_test.go │ │ ├── atomic_block.go │ │ ├── atomic_block_test.go │ │ ├── block.go │ │ ├── builder │ │ │ ├── builder.go │ │ │ ├── builder_test.go │ │ │ ├── helpers_test.go │ │ │ ├── main_test.go │ │ │ └── standard_block_test.go │ │ ├── codec.go │ │ ├── commit_block.go │ │ ├── commit_block_test.go │ │ ├── common_block.go │ │ ├── executor │ │ │ ├── README.md │ │ │ ├── acceptor.go │ │ │ ├── acceptor_test.go │ │ │ ├── backend.go │ │ │ ├── backend_test.go │ │ │ ├── block.go │ │ │ ├── block_state.go │ │ │ ├── block_test.go │ │ │ ├── helpers_test.go │ │ │ ├── manager.go │ │ │ ├── manager_test.go │ │ │ ├── mock_manager.go │ │ │ ├── options.go │ │ │ ├── options_test.go │ │ │ ├── proposal_block_test.go │ │ │ ├── rejector.go │ │ │ ├── rejector_test.go │ │ │ ├── standard_block_test.go │ │ │ ├── verifier.go │ │ │ └── verifier_test.go │ │ ├── mock_block.go │ │ ├── parse.go │ │ ├── parse_test.go │ │ ├── proposal_block.go │ │ ├── proposal_block_test.go │ │ ├── serialization_test.go │ │ ├── standard_block.go │ │ ├── standard_block_test.go │ │ └── visitor.go │ ├── client.go │ ├── client_permissionless_validator.go │ ├── config │ │ ├── config.go │ │ ├── config.md │ │ ├── execution_config.go │ │ └── execution_config_test.go │ ├── docs │ │ ├── block_formation_logic.md │ │ ├── chain_time_update.md │ │ ├── mempool_gossiping.md │ │ ├── subnets.md │ │ └── validators_versioning.md │ ├── factory.go │ ├── fx │ │ ├── fx.go │ │ └── mock_fx.go │ ├── genesis │ │ ├── codec.go │ │ └── genesis.go │ ├── health.go │ ├── main_test.go │ ├── metrics │ │ ├── block_metrics.go │ │ ├── metrics.go │ │ ├── no_op.go │ │ └── tx_metrics.go │ ├── network │ │ ├── config.go │ │ ├── gossip.go │ │ ├── gossip_test.go │ │ ├── main_test.go │ │ ├── network.go │ │ ├── network_test.go │ │ └── tx_verifier.go │ ├── reward │ │ ├── calculator.go │ │ ├── calculator_test.go │ │ └── config.go │ ├── service.go │ ├── service.md │ ├── service_test.go │ ├── signer │ │ ├── empty.go │ │ ├── empty_test.go │ │ ├── proof_of_possession.go │ │ ├── proof_of_possession_test.go │ │ └── signer.go │ ├── stakeable │ │ ├── stakeable_lock.go │ │ └── stakeable_lock_test.go │ ├── state │ │ ├── diff.go │ │ ├── diff_test.go │ │ ├── disk_staker_diff_iterator.go │ │ ├── disk_staker_diff_iterator_test.go │ │ ├── empty_iterator.go │ │ ├── empty_iterator_test.go │ │ ├── masked_iterator.go │ │ ├── masked_iterator_test.go │ │ ├── merged_iterator.go │ │ ├── merged_iterator_test.go │ │ ├── metadata_codec.go │ │ ├── metadata_delegator.go │ │ ├── metadata_delegator_test.go │ │ ├── metadata_validator.go │ │ ├── metadata_validator_test.go │ │ ├── mock_staker_iterator.go │ │ ├── mock_state.go │ │ ├── slice_iterator_test.go │ │ ├── staker.go │ │ ├── staker_diff_iterator.go │ │ ├── staker_diff_iterator_test.go │ │ ├── staker_status.go │ │ ├── staker_test.go │ │ ├── stakers.go │ │ ├── stakers_test.go │ │ ├── state.go │ │ ├── state_test.go │ │ ├── tree_iterator.go │ │ ├── tree_iterator_test.go │ │ └── versions.go │ ├── status │ │ ├── blockchain_status.go │ │ ├── blockchain_status_test.go │ │ ├── status.go │ │ └── status_test.go │ ├── txs │ │ ├── add_delegator_test.go │ │ ├── add_delegator_tx.go │ │ ├── add_permissionless_delegator_tx.go │ │ ├── add_permissionless_delegator_tx_test.go │ │ ├── add_permissionless_validator_tx.go │ │ ├── add_permissionless_validator_tx_test.go │ │ ├── add_subnet_validator_test.go │ │ ├── add_subnet_validator_tx.go │ │ ├── add_validator_test.go │ │ ├── add_validator_tx.go │ │ ├── advance_time_tx.go │ │ ├── base_tx.go │ │ ├── base_tx_test.go │ │ ├── codec.go │ │ ├── create_chain_test.go │ │ ├── create_chain_tx.go │ │ ├── create_subnet_tx.go │ │ ├── donation_tx.go │ │ ├── executor │ │ │ ├── advance_time_test.go │ │ │ ├── atomic_tx_executor.go │ │ │ ├── backend.go │ │ │ ├── create_chain_test.go │ │ │ ├── create_subnet_test.go │ │ │ ├── export_test.go │ │ │ ├── helpers_test.go │ │ │ ├── import_test.go │ │ │ ├── proposal_tx_executor.go │ │ │ ├── proposal_tx_executor_test.go │ │ │ ├── reward_validator_test.go │ │ │ ├── staker_tx_verification.go │ │ │ ├── staker_tx_verification_helpers.go │ │ │ ├── staker_tx_verification_test.go │ │ │ ├── standard_tx_executor.go │ │ │ ├── standard_tx_executor_test.go │ │ │ ├── state_changes.go │ │ │ └── subnet_tx_verification.go │ │ ├── export_tx.go │ │ ├── import_tx.go │ │ ├── mempool │ │ │ ├── mempool.go │ │ │ ├── mempool_test.go │ │ │ └── mock_mempool.go │ │ ├── mock_staker_tx.go │ │ ├── mock_unsigned_tx.go │ │ ├── priorities.go │ │ ├── priorities_test.go │ │ ├── remove_subnet_validator_tx.go │ │ ├── remove_subnet_validator_tx_test.go │ │ ├── reward_validator_tx.go │ │ ├── staker_tx.go │ │ ├── subnet_validator.go │ │ ├── subnet_validator_test.go │ │ ├── transfer_subnet_ownership_tx.go │ │ ├── transfer_subnet_ownership_tx_test.go │ │ ├── transform_subnet_tx.go │ │ ├── transform_subnet_tx_test.go │ │ ├── tx.go │ │ ├── txheap │ │ │ ├── by_end_time.go │ │ │ ├── by_end_time_test.go │ │ │ └── heap.go │ │ ├── txstest │ │ │ ├── backend.go │ │ │ ├── builder.go │ │ │ └── context.go │ │ ├── unsigned_tx.go │ │ ├── validator.go │ │ ├── validator_test.go │ │ └── visitor.go │ ├── utxo │ │ ├── mock_verifier.go │ │ ├── verifier.go │ │ └── verifier_test.go │ ├── validator_set_property_test.go │ ├── validators │ │ ├── manager.go │ │ ├── manager_benchmark_test.go │ │ └── test_manager.go │ ├── vm.go │ ├── vm_regression_test.go │ ├── vm_test.go │ └── warp │ │ ├── README.md │ │ ├── codec.go │ │ ├── constants.go │ │ ├── gwarp │ │ ├── client.go │ │ ├── server.go │ │ └── signer_test.go │ │ ├── message.go │ │ ├── message_test.go │ │ ├── payload │ │ ├── README.md │ │ ├── addressed_call.go │ │ ├── addressed_call_test.go │ │ ├── codec.go │ │ ├── hash.go │ │ ├── hash_test.go │ │ ├── payload.go │ │ └── payload_test.go │ │ ├── signature.go │ │ ├── signature_test.go │ │ ├── signer.go │ │ ├── signer_test.go │ │ ├── test_signer.go │ │ ├── unsigned_message.go │ │ ├── unsigned_message_test.go │ │ ├── validator.go │ │ └── validator_test.go ├── propertyfx │ ├── burn_operation.go │ ├── burn_operation_test.go │ ├── credential.go │ ├── credential_test.go │ ├── factory.go │ ├── factory_test.go │ ├── fx.go │ ├── fx_test.go │ ├── mint_operation.go │ ├── mint_operation_test.go │ ├── mint_output.go │ ├── mint_output_test.go │ ├── owned_output.go │ └── owned_output_test.go ├── proposervm │ ├── README.md │ ├── batched_vm.go │ ├── batched_vm_test.go │ ├── block.go │ ├── block │ │ ├── block.go │ │ ├── block_test.go │ │ ├── build.go │ │ ├── build_test.go │ │ ├── codec.go │ │ ├── header.go │ │ ├── header_test.go │ │ ├── option.go │ │ ├── option_test.go │ │ ├── parse.go │ │ └── parse_test.go │ ├── block_test.go │ ├── config.go │ ├── height_indexed_vm.go │ ├── main_test.go │ ├── mock_post_fork_block.go │ ├── post_fork_block.go │ ├── post_fork_block_test.go │ ├── post_fork_option.go │ ├── post_fork_option_test.go │ ├── pre_fork_block.go │ ├── pre_fork_block_test.go │ ├── proposer │ │ ├── mock_windower.go │ │ ├── validators.go │ │ ├── validators_test.go │ │ ├── windower.go │ │ └── windower_test.go │ ├── scheduler │ │ ├── mock_scheduler.go │ │ ├── scheduler.go │ │ └── scheduler_test.go │ ├── state │ │ ├── block_height_index.go │ │ ├── block_state.go │ │ ├── block_state_test.go │ │ ├── chain_state.go │ │ ├── chain_state_test.go │ │ ├── codec.go │ │ ├── mock_state.go │ │ ├── state.go │ │ └── state_test.go │ ├── state_summary.go │ ├── state_syncable_vm.go │ ├── state_syncable_vm_test.go │ ├── summary │ │ ├── build.go │ │ ├── build_test.go │ │ ├── codec.go │ │ ├── parse.go │ │ ├── parse_test.go │ │ └── state_summary.go │ ├── tree │ │ ├── tree.go │ │ └── tree_test.go │ ├── vm.go │ ├── vm_byzantine_test.go │ └── vm_test.go ├── registry │ ├── mock_vm_getter.go │ ├── mock_vm_registry.go │ ├── vm_getter.go │ ├── vm_getter_test.go │ ├── vm_registry.go │ └── vm_registry_test.go ├── rpcchainvm │ ├── batched_vm_test.go │ ├── errors.go │ ├── factory.go │ ├── ghttp │ │ ├── gconn │ │ │ ├── conn_client.go │ │ │ └── conn_server.go │ │ ├── greader │ │ │ ├── reader_client.go │ │ │ └── reader_server.go │ │ ├── gresponsewriter │ │ │ ├── locked_writer.go │ │ │ ├── writer_client.go │ │ │ └── writer_server.go │ │ ├── gwriter │ │ │ ├── writer_client.go │ │ │ └── writer_server.go │ │ ├── http_client.go │ │ ├── http_server.go │ │ └── http_test.go │ ├── grpcutils │ │ ├── client.go │ │ ├── client_test.go │ │ ├── server.go │ │ ├── server_closer.go │ │ └── util.go │ ├── gruntime │ │ ├── runtime_client.go │ │ └── runtime_server.go │ ├── messenger │ │ ├── messenger_client.go │ │ └── messenger_server.go │ ├── runtime │ │ ├── README.md │ │ ├── manager.go │ │ ├── runtime.go │ │ └── subprocess │ │ │ ├── initializer.go │ │ │ ├── linux_stopper.go │ │ │ ├── non_linux_stopper.go │ │ │ ├── runtime.go │ │ │ └── stopper.go │ ├── state_syncable_vm_test.go │ ├── vm.go │ ├── vm_client.go │ ├── vm_server.go │ ├── vm_test.go │ └── with_context_vm_test.go ├── secp256k1fx │ ├── credential.go │ ├── credential_test.go │ ├── factory.go │ ├── factory_test.go │ ├── fx.go │ ├── fx_test.go │ ├── input.go │ ├── input_test.go │ ├── keychain.go │ ├── keychain_test.go │ ├── mint_operation.go │ ├── mint_operation_test.go │ ├── mint_output.go │ ├── mint_output_test.go │ ├── output_owners.go │ ├── output_owners_test.go │ ├── transfer_input.go │ ├── transfer_input_test.go │ ├── transfer_output.go │ ├── transfer_output_test.go │ ├── tx.go │ └── vm.go ├── tracedvm │ ├── batched_vm.go │ ├── block.go │ ├── block_vm.go │ ├── build_block_with_context_vm.go │ ├── state_syncable_vm.go │ ├── tx.go │ └── vertex_vm.go └── types │ └── blob_data.go ├── wallet ├── chain │ ├── c │ │ ├── backend.go │ │ ├── builder.go │ │ ├── builder_with_options.go │ │ ├── context.go │ │ ├── signer.go │ │ ├── wallet.go │ │ └── wallet_with_options.go │ ├── p │ │ ├── backend.go │ │ ├── backend_visitor.go │ │ ├── builder │ │ │ ├── builder.go │ │ │ ├── builder_with_options.go │ │ │ └── context.go │ │ ├── builder_test.go │ │ ├── signer │ │ │ ├── signer.go │ │ │ └── visitor.go │ │ ├── wallet.go │ │ └── wallet_with_options.go │ └── x │ │ ├── backend.go │ │ ├── backend_visitor.go │ │ ├── builder │ │ ├── builder.go │ │ ├── builder_with_options.go │ │ ├── constants.go │ │ └── context.go │ │ ├── builder_test.go │ │ ├── context.go │ │ ├── signer │ │ ├── signer.go │ │ └── visitor.go │ │ ├── wallet.go │ │ └── wallet_with_options.go └── supernet │ └── primary │ ├── api.go │ ├── common │ ├── options.go │ ├── spend.go │ ├── test_utxos.go │ └── utxos.go │ ├── example_test.go │ ├── examples │ ├── add-permissioned-subnet-validator │ │ └── main.go │ ├── add-primary-validator │ │ └── main.go │ ├── c-chain-export │ │ └── main.go │ ├── c-chain-import │ │ └── main.go │ ├── create-asset │ │ └── main.go │ ├── create-chain │ │ └── main.go │ ├── create-locked-stakeable │ │ └── main.go │ ├── create-subnet │ │ └── main.go │ ├── get-p-chain-balance │ │ └── main.go │ ├── get-x-chain-balance │ │ └── main.go │ └── remove-subnet-validator │ │ └── main.go │ └── wallet.go └── x ├── README.md ├── archivedb ├── batch.go ├── db.go ├── db_test.go ├── key.go ├── key_test.go ├── prefix_test.go ├── reader.go └── value.go ├── merkledb ├── README.md ├── batch.go ├── bytes_pool.go ├── bytes_pool_test.go ├── cache.go ├── cache_test.go ├── codec.go ├── codec_test.go ├── db.go ├── db_test.go ├── hashing.go ├── hashing_test.go ├── helpers_test.go ├── history.go ├── history_test.go ├── intermediate_node_db.go ├── intermediate_node_db_test.go ├── key.go ├── key_test.go ├── metrics.go ├── metrics_test.go ├── mock_db.go ├── node.go ├── node_test.go ├── proof.go ├── proof_test.go ├── tracer.go ├── trie.go ├── trie_test.go ├── value_node_db.go ├── value_node_db_test.go ├── view.go ├── view_iterator.go ├── view_iterator_test.go ├── view_test.go ├── wait_group.go └── wait_group_test.go └── sync ├── README.md ├── client.go ├── client_test.go ├── db.go ├── g_db ├── db_client.go └── db_server.go ├── manager.go ├── metrics.go ├── mock_client.go ├── mock_network_client.go ├── network_client.go ├── network_server.go ├── network_server_test.go ├── response_handler.go ├── sync_test.go ├── workheap.go └── workheap_test.go /.dockerignore: -------------------------------------------------------------------------------- 1 | .ci 2 | .github 3 | .gitignore 4 | .golangci.yml 5 | 6 | .idea 7 | .vscode 8 | 9 | LICENSE 10 | *.md 11 | 12 | Dockerfile 13 | 14 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # https://editorconfig.org/ 2 | 3 | [*] 4 | end_of_line = lf 5 | insert_final_newline = true 6 | trim_trailing_newspace = true 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | *~ 3 | .DS_Store 4 | 5 | awscpu 6 | 7 | # Binaries for programs and plugins 8 | *.exe 9 | *.exe~ 10 | *.dll 11 | *.so 12 | *.dylib 13 | *.profile 14 | 15 | # Test binary, build with `go test -c` 16 | *.test 17 | tmp/ 18 | 19 | # Output of the go coverage tool, specifically when used with LiteIDE 20 | *.out 21 | 22 | # ignore GoLand metafiles directory 23 | .idea/ 24 | 25 | *logs/ 26 | 27 | .vscode* 28 | 29 | *.pb* 30 | 31 | db* 32 | 33 | *cpu[0-9]* 34 | *mem[0-9]* 35 | *lock[0-9]* 36 | *.profile 37 | *.swp 38 | *.aux 39 | *.fdb* 40 | *.fls 41 | *.gz 42 | *.pdf 43 | 44 | .coverage 45 | 46 | bin/ 47 | build/ 48 | 49 | keys/staker.* 50 | 51 | !*.go 52 | !*.proto 53 | 54 | plugins/ 55 | 56 | scripts/ansible/*inventory.yml 57 | scripts/.build_image_gopath/ 58 | 59 | tests/e2e/e2e.test 60 | tests/upgrade/upgrade.test 61 | 62 | vendor 63 | 64 | **/testdata 65 | -------------------------------------------------------------------------------- /api/admin/key_value_reader.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /api/health/checker.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /api/health/metrics.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package health 5 | 6 | import "github.com/prometheus/client_golang/prometheus" 7 | 8 | type metrics struct { 9 | // failingChecks keeps track of the number of check failing 10 | failingChecks *prometheus.GaugeVec 11 | } 12 | 13 | func newMetrics(namespace string, registerer prometheus.Registerer) (*metrics, error) { 14 | metrics := &metrics{ 15 | failingChecks: prometheus.NewGaugeVec( 16 | prometheus.GaugeOpts{ 17 | Namespace: namespace, 18 | Name: "checks_failing", 19 | Help: "number of currently failing health checks", 20 | }, 21 | []string{"tag"}, 22 | ), 23 | } 24 | metrics.failingChecks.WithLabelValues(AllTag).Set(0) 25 | metrics.failingChecks.WithLabelValues(ApplicationTag).Set(0) 26 | return metrics, registerer.Register(metrics.failingChecks) 27 | } 28 | -------------------------------------------------------------------------------- /api/keystore/codec.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package keystore 5 | 6 | import ( 7 | "github.com/Juneo-io/juneogo/codec" 8 | "github.com/Juneo-io/juneogo/codec/linearcodec" 9 | "github.com/Juneo-io/juneogo/utils/units" 10 | ) 11 | 12 | const ( 13 | CodecVersion = 0 14 | 15 | maxPackerSize = 1 * units.GiB // max size, in bytes, of something being marshalled by Marshal() 16 | ) 17 | 18 | var Codec codec.Manager 19 | 20 | func init() { 21 | lc := linearcodec.NewDefault() 22 | Codec = codec.NewManager(maxPackerSize) 23 | if err := Codec.RegisterCodec(CodecVersion, lc); err != nil { 24 | panic(err) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /api/metrics/gatherer_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package metrics 5 | 6 | import ( 7 | dto "github.com/prometheus/client_model/go" 8 | ) 9 | 10 | var ( 11 | hello = "hello" 12 | world = "world" 13 | helloWorld = "hello_world" 14 | ) 15 | 16 | type testGatherer struct { 17 | mfs []*dto.MetricFamily 18 | err error 19 | } 20 | 21 | func (g *testGatherer) Gather() ([]*dto.MetricFamily, error) { 22 | return g.mfs, g.err 23 | } 24 | -------------------------------------------------------------------------------- /cache/empty_cache.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package cache 5 | 6 | import "github.com/Juneo-io/juneogo/utils" 7 | 8 | var _ Cacher[struct{}, struct{}] = (*Empty[struct{}, struct{}])(nil) 9 | 10 | type Empty[K any, V any] struct{} 11 | 12 | func (*Empty[K, V]) Put(K, V) {} 13 | 14 | func (*Empty[K, V]) Get(K) (V, bool) { 15 | return utils.Zero[V](), false 16 | } 17 | 18 | func (*Empty[K, _]) Evict(K) {} 19 | 20 | func (*Empty[_, _]) Flush() {} 21 | 22 | func (*Empty[_, _]) Len() int { 23 | return 0 24 | } 25 | 26 | func (*Empty[_, _]) PortionFilled() float64 { 27 | return 0 28 | } 29 | -------------------------------------------------------------------------------- /chains/atomic/codec.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/codec" 10 | "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /chains/atomic/shared_memory_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package atomic 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/Juneo-io/juneogo/database/memdb" 10 | "github.com/Juneo-io/juneogo/database/prefixdb" 11 | "github.com/Juneo-io/juneogo/ids" 12 | ) 13 | 14 | func TestSharedMemory(t *testing.T) { 15 | chainID0 := ids.GenerateTestID() 16 | chainID1 := ids.GenerateTestID() 17 | 18 | for _, test := range SharedMemoryTests { 19 | baseDB := memdb.New() 20 | 21 | memoryDB := prefixdb.New([]byte{0}, baseDB) 22 | testDB := prefixdb.New([]byte{1}, baseDB) 23 | 24 | m := NewMemory(memoryDB) 25 | 26 | sm0 := m.NewSharedMemory(chainID0) 27 | sm1 := m.NewSharedMemory(chainID1) 28 | 29 | test(t, chainID0, chainID1, sm0, sm1, testDB) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /chains/atomic/writer.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package atomic 5 | 6 | import "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /chains/registrant.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package chains 5 | 6 | import ( 7 | "github.com/Juneo-io/juneogo/snow" 8 | "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /codec/general_codec.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /codec/hierarchycodec/codec_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/codec" 10 | ) 11 | 12 | func TestVectors(t *testing.T) { 13 | for _, test := range codec.Tests { 14 | c := NewDefault() 15 | test(c, t) 16 | } 17 | } 18 | 19 | func TestMultipleTags(t *testing.T) { 20 | for _, test := range codec.MultipleTagsTests { 21 | c := New([]string{"tag1", "tag2"}) 22 | test(c, t) 23 | } 24 | } 25 | 26 | func FuzzStructUnmarshalHierarchyCodec(f *testing.F) { 27 | c := NewDefault() 28 | codec.FuzzStructUnmarshal(c, f) 29 | } 30 | -------------------------------------------------------------------------------- /codec/linearcodec/codec_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/codec" 10 | ) 11 | 12 | func TestVectors(t *testing.T) { 13 | for _, test := range codec.Tests { 14 | c := NewDefault() 15 | test(c, t) 16 | } 17 | } 18 | 19 | func TestMultipleTags(t *testing.T) { 20 | for _, test := range codec.MultipleTagsTests { 21 | c := New([]string{"tag1", "tag2"}) 22 | test(c, t) 23 | } 24 | } 25 | 26 | func FuzzStructUnmarshalLinearCodec(f *testing.F) { 27 | c := NewDefault() 28 | codec.FuzzStructUnmarshal(c, f) 29 | } 30 | -------------------------------------------------------------------------------- /codec/registry.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /database/common.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /database/encdb/codec.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package encdb 5 | 6 | import ( 7 | "github.com/Juneo-io/juneogo/codec" 8 | "github.com/Juneo-io/juneogo/codec/linearcodec" 9 | ) 10 | 11 | const CodecVersion = 0 12 | 13 | var Codec codec.Manager 14 | 15 | func init() { 16 | lc := linearcodec.NewDefault() 17 | Codec = codec.NewDefaultManager() 18 | 19 | if err := Codec.RegisterCodec(CodecVersion, lc); err != nil { 20 | panic(err) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /database/errors.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /database/linkeddb/codec.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/codec" 10 | "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /database/rpcdb/errors.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package rpcdb 5 | 6 | import ( 7 | "github.com/Juneo-io/juneogo/database" 8 | 9 | rpcdbpb "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /genesis/bootstrappers_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/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.TestnetID { 23 | require.Len(bootstrappers, length) 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /genesis/validators.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package genesis 5 | 6 | import ( 7 | "encoding/json" 8 | "fmt" 9 | 10 | _ "embed" 11 | 12 | "github.com/Juneo-io/juneogo/ids" 13 | "github.com/Juneo-io/juneogo/utils/constants" 14 | "github.com/Juneo-io/juneogo/utils/set" 15 | ) 16 | 17 | var ( 18 | //go:embed validators.json 19 | validatorsPerNetworkJSON []byte 20 | 21 | validatorsPerNetwork map[string]set.Set[ids.NodeID] 22 | ) 23 | 24 | func init() { 25 | if err := json.Unmarshal(validatorsPerNetworkJSON, &validatorsPerNetwork); err != nil { 26 | panic(fmt.Sprintf("failed to decode validators.json: %v", err)) 27 | } 28 | } 29 | 30 | // GetValidators returns recent validators for the requested network. 31 | func GetValidators(networkID uint32) set.Set[ids.NodeID] { 32 | networkName := constants.NetworkIDToNetworkName[networkID] 33 | return validatorsPerNetwork[networkName] 34 | } 35 | -------------------------------------------------------------------------------- /header.yml: -------------------------------------------------------------------------------- 1 | header: | 2 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 3 | // See the file LICENSE for licensing terms. 4 | -------------------------------------------------------------------------------- /ids/aliases_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package ids 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/stretchr/testify/require" 10 | ) 11 | 12 | func TestAliaser(t *testing.T) { 13 | require := require.New(t) 14 | for _, test := range AliasTests { 15 | aliaser := NewAliaser() 16 | test(require, aliaser, aliaser) 17 | } 18 | } 19 | 20 | func TestPrimaryAliasOrDefaultTest(t *testing.T) { 21 | require := require.New(t) 22 | aliaser := NewAliaser() 23 | id1 := ID{'J', 'a', 'm', 'e', 's', ' ', 'G', 'o', 'r', 'd', 'o', 'n'} 24 | id2 := ID{'B', 'r', 'u', 'c', 'e', ' ', 'W', 'a', 'y', 'n', 'e'} 25 | require.NoError(aliaser.Alias(id2, "Batman")) 26 | 27 | require.NoError(aliaser.Alias(id2, "Dark Knight")) 28 | 29 | res := aliaser.PrimaryAliasOrDefault(id1) 30 | require.Equal(res, id1.String()) 31 | 32 | expected := "Batman" 33 | require.Equal(expected, aliaser.PrimaryAliasOrDefault(id2)) 34 | } 35 | -------------------------------------------------------------------------------- /ids/request_id.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 this request came from 11 | SourceChainID ID 12 | // The chain the expected response should come from 13 | DestinationChainID ID 14 | // The unique identifier for this request 15 | RequestID uint32 16 | // The message opcode 17 | Op byte 18 | } 19 | -------------------------------------------------------------------------------- /indexer/codec.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/codec" 10 | "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /indexer/container.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package indexer 5 | 6 | import "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /main/default.pgo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Juneo-io/juneogo/494e542f7120bcfbd69caf9e586c2f0d737af939/main/default.pgo -------------------------------------------------------------------------------- /network/conn_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /network/handler_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package network 5 | 6 | import ( 7 | "github.com/Juneo-io/juneogo/ids" 8 | "github.com/Juneo-io/juneogo/snow/networking/router" 9 | "github.com/Juneo-io/juneogo/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, supernetID ids.ID) 17 | DisconnectedF func(nodeID ids.NodeID) 18 | } 19 | 20 | func (h *testHandler) Connected(id ids.NodeID, nodeVersion *version.Application, supernetID ids.ID) { 21 | if h.ConnectedF != nil { 22 | h.ConnectedF(id, nodeVersion, supernetID) 23 | } 24 | } 25 | 26 | func (h *testHandler) Disconnected(id ids.NodeID) { 27 | if h.DisconnectedF != nil { 28 | h.DisconnectedF(id) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /network/p2p/node_sampler.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /network/peer/test_network.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package peer 5 | 6 | import ( 7 | "github.com/Juneo-io/juneogo/ids" 8 | "github.com/Juneo-io/juneogo/utils/bloom" 9 | "github.com/Juneo-io/juneogo/utils/ips" 10 | ) 11 | 12 | var TestNetwork Network = testNetwork{} 13 | 14 | type testNetwork struct{} 15 | 16 | func (testNetwork) Connected(ids.NodeID) {} 17 | 18 | func (testNetwork) AllowConnection(ids.NodeID) bool { 19 | return true 20 | } 21 | 22 | func (testNetwork) Track([]*ips.ClaimedIPPort) error { 23 | return nil 24 | } 25 | 26 | func (testNetwork) Disconnected(ids.NodeID) {} 27 | 28 | func (testNetwork) KnownPeers() ([]byte, []byte) { 29 | return bloom.EmptyFilter.Marshal(), nil 30 | } 31 | 32 | func (testNetwork) Peers(ids.NodeID, *bloom.ReadFilter, []byte) []*ips.ClaimedIPPort { 33 | return nil 34 | } 35 | -------------------------------------------------------------------------------- /network/throttling/no_inbound_msg_throttler.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /network/throttling/release_func.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /proto/Dockerfile.buf: -------------------------------------------------------------------------------- 1 | FROM bufbuild/buf:1.31.0 AS builder 2 | 3 | FROM ubuntu:20.04 4 | 5 | RUN apt-get update && apt -y install bash curl unzip git 6 | WORKDIR /opt 7 | 8 | RUN \ 9 | curl -L https://go.dev/dl/go1.21.9.linux-amd64.tar.gz > golang.tar.gz && \ 10 | mkdir golang && \ 11 | tar -zxvf golang.tar.gz -C golang/ 12 | 13 | ENV PATH="${PATH}:/opt/golang/go/bin" 14 | 15 | COPY --from=builder /usr/local/bin/buf /usr/local/bin/ 16 | 17 | # any version changes here should also be bumped in scripts/protobuf_codegen.sh 18 | RUN \ 19 | go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.33.0 && \ 20 | go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.3.0 21 | 22 | ENV PATH="${PATH}:/root/go/bin/" 23 | -------------------------------------------------------------------------------- /proto/aliasreader/aliasreader.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package aliasreader; 4 | 5 | option go_package = "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /proto/buf.md: -------------------------------------------------------------------------------- 1 | README.md -------------------------------------------------------------------------------- /proto/io/reader/reader.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package io.reader; 4 | 5 | option go_package = "github.com/Juneo-io/juneogo/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 | optional string error = 2; 22 | } 23 | -------------------------------------------------------------------------------- /proto/io/writer/writer.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package io.writer; 4 | 5 | option go_package = "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /proto/keystore/keystore.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package keystore; 4 | 5 | option go_package = "github.com/Juneo-io/juneogo/proto/pb/keystore"; 6 | 7 | service Keystore { 8 | rpc GetDatabase(GetDatabaseRequest) returns (GetDatabaseResponse); 9 | } 10 | 11 | message GetDatabaseRequest { 12 | string username = 1; 13 | string password = 2; 14 | } 15 | 16 | message GetDatabaseResponse { 17 | // reserved for backward compatibility 18 | // avalanchego <=v1.7.9 used the field "1" as an id to identify the gRPC server 19 | // address which served the Database service via the now removed service broker 20 | reserved 1; 21 | // server_addr is the address of the gRPC server hosting the Database service 22 | string server_addr = 2; 23 | } 24 | -------------------------------------------------------------------------------- /proto/messenger/messenger.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package messenger; 4 | 5 | option go_package = "github.com/Juneo-io/juneogo/proto/pb/messenger"; 6 | 7 | service Messenger { 8 | rpc Notify(NotifyRequest) returns (NotifyResponse); 9 | } 10 | 11 | enum Message { 12 | MESSAGE_UNSPECIFIED = 0; 13 | MESSAGE_BUILD_BLOCK = 1; 14 | MESSAGE_STATE_SYNC_FINISHED = 2; 15 | } 16 | 17 | message NotifyRequest { 18 | Message message = 1; 19 | } 20 | 21 | message NotifyResponse {} 22 | -------------------------------------------------------------------------------- /proto/sdk/sdk.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package sdk; 4 | 5 | option go_package = "github.com/Juneo-io/juneogo/proto/pb/sdk"; 6 | 7 | message PullGossipRequest { 8 | // TODO: Remove reservation after v1.11.x activates. 9 | reserved 1; 10 | bytes salt = 2; 11 | bytes filter = 3; 12 | } 13 | 14 | message PullGossipResponse { 15 | repeated bytes gossip = 1; 16 | } 17 | 18 | message PushGossip { 19 | repeated bytes gossip = 1; 20 | } 21 | -------------------------------------------------------------------------------- /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/Juneo-io/juneogo/proto/pb/vm/manager"; 8 | 9 | // Manages the lifecycle of a supernet 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 | -------------------------------------------------------------------------------- /proto/warp/message.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package warp; 4 | 5 | option go_package = "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /pubsub/bloom/filter_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/utils/units" 12 | ) 13 | 14 | func TestNew(t *testing.T) { 15 | var ( 16 | require = require.New(t) 17 | maxN = 10000 18 | p = 0.1 19 | maxBytes = 1 * units.MiB // 1 MiB 20 | ) 21 | f, err := New(maxN, p, maxBytes) 22 | require.NoError(err) 23 | require.NotNil(f) 24 | 25 | f.Add([]byte("hello")) 26 | 27 | checked := f.Check([]byte("hello")) 28 | require.True(checked, "should have contained the key") 29 | 30 | checked = f.Check([]byte("bye")) 31 | require.False(checked, "shouldn't have contained the key") 32 | } 33 | -------------------------------------------------------------------------------- /pubsub/bloom/map_filter.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package bloom 5 | 6 | import ( 7 | "sync" 8 | 9 | "github.com/Juneo-io/juneogo/utils/set" 10 | ) 11 | 12 | type mapFilter struct { 13 | lock sync.RWMutex 14 | values set.Set[string] 15 | } 16 | 17 | func NewMap() Filter { 18 | return &mapFilter{} 19 | } 20 | 21 | func (m *mapFilter) Add(bl ...[]byte) { 22 | m.lock.Lock() 23 | defer m.lock.Unlock() 24 | 25 | for _, b := range bl { 26 | m.values.Add(string(b)) 27 | } 28 | } 29 | 30 | func (m *mapFilter) Check(b []byte) bool { 31 | m.lock.RLock() 32 | defer m.lock.RUnlock() 33 | 34 | return m.values.Contains(string(b)) 35 | } 36 | -------------------------------------------------------------------------------- /pubsub/filterer.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package pubsub 5 | 6 | type Filterer interface { 7 | Filter(connections []Filter) ([]bool, interface{}) 8 | } 9 | -------------------------------------------------------------------------------- /scripts/mocks.mockgen.source.txt: -------------------------------------------------------------------------------- 1 | snow/engine/common/sender.go=StateSummarySender,AcceptedStateSummarySender,FrontierSender,AcceptedSender,FetchSender,AppSender,QuerySender,CrossChainAppSender,NetworkAppSender,Gossiper=snow/engine/common/mock_sender.go 2 | snow/networking/router/router.go=InternalHandler=snow/networking/router/mock_router.go 3 | snow/networking/sender/external_sender.go==snow/networking/sender/mock_external_sender.go 4 | vms/avm/block/executor/manager.go==vms/avm/block/executor/mock_manager.go 5 | vms/avm/txs/tx.go==vms/avm/txs/mock_unsigned_tx.go 6 | vms/platformvm/block/executor/manager.go==vms/platformvm/block/executor/mock_manager.go 7 | vms/platformvm/txs/staker_tx.go=ValidatorTx,DelegatorTx,StakerTx,PermissionlessStaker=vms/platformvm/txs/mock_staker_tx.go 8 | vms/platformvm/txs/unsigned_tx.go==vms/platformvm/txs/mock_unsigned_tx.go 9 | x/merkledb/db.go=ChangeProofer,RangeProofer,Clearer,Prefetcher=x/merkledb/mock_db.go 10 | -------------------------------------------------------------------------------- /scripts/tbd/build_avalanche.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | 5 | print_usage() { 6 | printf "Usage: build_avalanche [OPTIONS] 7 | 8 | Build avalanchego 9 | 10 | Options: 11 | 12 | -r Build with race detector 13 | " 14 | } 15 | 16 | race='' 17 | while getopts 'r' flag; do 18 | case "${flag}" in 19 | r) race='-race' ;; 20 | *) print_usage 21 | exit 1 ;; 22 | esac 23 | done 24 | 25 | # Avalanchego root folder 26 | AVALANCHE_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd ) 27 | # Load the constants 28 | source "$AVALANCHE_PATH"/scripts/constants.sh 29 | 30 | build_args="$race" 31 | echo "Building AvalancheGo..." 32 | go build $build_args -ldflags "-X github.com/ava-labs/avalanchego/version.GitCommit=$git_commit $static_ld_flags" -o "$avalanchego_path" "$AVALANCHE_PATH/main/"*.go 33 | -------------------------------------------------------------------------------- /scripts/tbd/build_test.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 | EXCLUDED_TARGETS="| grep -v /mocks | grep -v proto | grep -v tests/e2e | grep -v tests/upgrade" 11 | 12 | GOOS=$(go env GOOS) 13 | if [[ "$GOOS" == "windows" ]]; then 14 | # tmpnet is not compatible with windows 15 | EXCLUDED_TARGETS="${EXCLUDED_TARGETS} | grep -v tests/fixture" 16 | fi 17 | 18 | TEST_TARGETS="$(eval "go list ./... ${EXCLUDED_TARGETS}")" 19 | 20 | # shellcheck disable=SC2086 21 | go test -shuffle=on -race -timeout="${TIMEOUT:-120s}" -coverprofile="coverage.out" -covermode="atomic" ${TEST_TARGETS} 22 | -------------------------------------------------------------------------------- /scripts/tbd/build_xsvm.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | 5 | if ! [[ "$0" =~ scripts/build_xsvm.sh ]]; then 6 | echo "must be run from repository root" 7 | exit 255 8 | fi 9 | 10 | source ./scripts/constants.sh 11 | 12 | echo "Building xsvm plugin..." 13 | go build -o ./build/xsvm ./vms/example/xsvm/cmd/xsvm/ 14 | 15 | PLUGIN_DIR="$HOME/.avalanchego/plugins" 16 | PLUGIN_PATH="${PLUGIN_DIR}/v3m4wPxaHpvGr8qfMeyK6PRW3idZrPHmYcMTt7oXdK47yurVH" 17 | echo "Symlinking ./build/xsvm to ${PLUGIN_PATH}" 18 | mkdir -p "${PLUGIN_DIR}" 19 | ln -sf "${PWD}/build/xsvm" "${PLUGIN_PATH}" 20 | -------------------------------------------------------------------------------- /snow/consensus/snowball/binary_slush.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /snow/consensus/snowball/factory.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package snowball 5 | 6 | import "github.com/Juneo-io/juneogo/ids" 7 | 8 | var ( 9 | SnowballFactory Factory = snowballFactory{} 10 | SnowflakeFactory Factory = snowflakeFactory{} 11 | ) 12 | 13 | type snowballFactory struct{} 14 | 15 | func (snowballFactory) NewNnary(params Parameters, choice ids.ID) Nnary { 16 | sb := newNnarySnowball(params.Beta, choice) 17 | return &sb 18 | } 19 | 20 | func (snowballFactory) NewUnary(params Parameters) Unary { 21 | sb := newUnarySnowball(params.Beta) 22 | return &sb 23 | } 24 | 25 | type snowflakeFactory struct{} 26 | 27 | func (snowflakeFactory) NewNnary(params Parameters, choice ids.ID) Nnary { 28 | sf := newNnarySnowflake(params.Beta, choice) 29 | return &sf 30 | } 31 | 32 | func (snowflakeFactory) NewUnary(params Parameters) Unary { 33 | sf := newUnarySnowflake(params.Beta) 34 | return &sf 35 | } 36 | -------------------------------------------------------------------------------- /snow/consensus/snowman/bootstrapper/noop.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/ids" 10 | "github.com/Juneo-io/juneogo/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/consensus/snowman/bootstrapper/noop_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /snow/consensus/snowman/bootstrapper/poll.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/ids" 10 | "github.com/Juneo-io/juneogo/utils/set" 11 | ) 12 | 13 | type Poll interface { 14 | // GetPeers returns the set of peers whose opinion should be requested. It 15 | // is expected to repeatedly call this function along with [RecordOpinion] 16 | // until [Result] returns finalized. 17 | GetPeers(ctx context.Context) (peers set.Set[ids.NodeID]) 18 | // RecordOpinion of a node whose opinion was requested. 19 | RecordOpinion(ctx context.Context, nodeID ids.NodeID, blkIDs set.Set[ids.ID]) error 20 | // Result returns the evaluation of all the peer's opinions along with a 21 | // flag to identify that the result has finished being calculated. 22 | Result(ctx context.Context) (blkIDs []ids.ID, finalized bool) 23 | } 24 | -------------------------------------------------------------------------------- /snow/consensus/snowman/bootstrapper/poll_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package bootstrapper 5 | 6 | import "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /snow/consensus/snowman/factory.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /snow/consensus/snowman/oracle_block.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/consensus/snowman/poll/interfaces.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package poll 5 | 6 | import ( 7 | "fmt" 8 | 9 | "github.com/Juneo-io/juneogo/ids" 10 | "github.com/Juneo-io/juneogo/utils/bag" 11 | "github.com/Juneo-io/juneogo/utils/formatting" 12 | ) 13 | 14 | // Set is a collection of polls 15 | type Set interface { 16 | fmt.Stringer 17 | 18 | Add(requestID uint32, vdrs bag.Bag[ids.NodeID]) bool 19 | Vote(requestID uint32, vdr ids.NodeID, vote ids.ID) []bag.Bag[ids.ID] 20 | Drop(requestID uint32, vdr ids.NodeID) []bag.Bag[ids.ID] 21 | Len() int 22 | } 23 | 24 | // Poll is an outstanding poll 25 | type Poll interface { 26 | formatting.PrefixedStringer 27 | 28 | Vote(vdr ids.NodeID, vote ids.ID) 29 | Drop(vdr ids.NodeID) 30 | Finished() bool 31 | Result() bag.Bag[ids.ID] 32 | } 33 | 34 | // Factory creates a new Poll 35 | type Factory interface { 36 | New(vdrs bag.Bag[ids.NodeID]) Poll 37 | } 38 | -------------------------------------------------------------------------------- /snow/consensus/snowman/topological_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package snowman 5 | 6 | import "testing" 7 | 8 | func TestTopological(t *testing.T) { 9 | runConsensusTests(t, TopologicalFactory{}) 10 | } 11 | -------------------------------------------------------------------------------- /snow/consensus/snowstorm/test_tx.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/ids" 10 | "github.com/Juneo-io/juneogo/snow/choices" 11 | "github.com/Juneo-io/juneogo/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/avalanche/bootstrap/queue/job.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/ids" 10 | "github.com/Juneo-io/juneogo/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/engine/avalanche/bootstrap/queue/parser.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /snow/engine/avalanche/bootstrap/queue/test_parser.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /snow/engine/avalanche/vertex/manager.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/parser.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/snow/consensus/avalanche" 10 | "github.com/Juneo-io/juneogo/utils/hashing" 11 | ) 12 | 13 | // Parser parses bytes into a vertex. 14 | type Parser interface { 15 | // Parse a vertex from a slice of bytes 16 | ParseVtx(ctx context.Context, vertex []byte) (avalanche.Vertex, error) 17 | } 18 | 19 | // Parse parses the provided vertex bytes into a stateless vertex 20 | func Parse(bytes []byte) (StatelessVertex, error) { 21 | vtx := innerStatelessVertex{} 22 | version, err := Codec.Unmarshal(bytes, &vtx) 23 | if err != nil { 24 | return nil, err 25 | } 26 | vtx.Version = version 27 | 28 | return statelessVertex{ 29 | innerStatelessVertex: vtx, 30 | id: hashing.ComputeHash256Array(bytes), 31 | bytes: bytes, 32 | }, nil 33 | } 34 | -------------------------------------------------------------------------------- /snow/engine/avalanche/vertex/parser_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package vertex 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/stretchr/testify/require" 10 | 11 | "github.com/Juneo-io/juneogo/codec" 12 | "github.com/Juneo-io/juneogo/ids" 13 | ) 14 | 15 | func TestParseInvalid(t *testing.T) { 16 | vtxBytes := []byte{1, 2, 3, 4, 5} 17 | _, err := Parse(vtxBytes) 18 | require.ErrorIs(t, err, codec.ErrUnknownVersion) 19 | } 20 | 21 | func TestParseValid(t *testing.T) { 22 | require := require.New(t) 23 | 24 | chainID := ids.ID{1} 25 | height := uint64(2) 26 | parentIDs := []ids.ID{{4}, {5}} 27 | txs := [][]byte{{6}, {7}} 28 | vtx, err := Build( 29 | chainID, 30 | height, 31 | parentIDs, 32 | txs, 33 | ) 34 | require.NoError(err) 35 | 36 | vtxBytes := vtx.Bytes() 37 | parsedVtx, err := Parse(vtxBytes) 38 | require.NoError(err) 39 | require.Equal(vtx, parsedVtx) 40 | } 41 | -------------------------------------------------------------------------------- /snow/engine/avalanche/vertex/storage.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/ids" 10 | "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /snow/engine/avalanche/vertex/test_manager.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package vertex 5 | 6 | import "testing" 7 | 8 | var _ Manager = (*TestManager)(nil) 9 | 10 | type TestManager struct { 11 | TestBuilder 12 | TestParser 13 | TestStorage 14 | } 15 | 16 | func NewTestManager(t *testing.T) *TestManager { 17 | return &TestManager{ 18 | TestBuilder: TestBuilder{T: t}, 19 | TestParser: TestParser{T: t}, 20 | TestStorage: TestStorage{T: t}, 21 | } 22 | } 23 | 24 | func (m *TestManager) Default(cant bool) { 25 | m.TestBuilder.Default(cant) 26 | m.TestParser.Default(cant) 27 | m.TestStorage.Default(cant) 28 | } 29 | -------------------------------------------------------------------------------- /snow/engine/common/bootstrap_tracker.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package common 5 | 6 | import "github.com/Juneo-io/juneogo/ids" 7 | 8 | // BootstrapTracker describes the standard interface for tracking the status of 9 | // a supernet 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 | OnBootstrapCompleted() chan struct{} 18 | } 19 | -------------------------------------------------------------------------------- /snow/engine/common/bootstrapable.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /snow/engine/common/fx.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package common 5 | 6 | import "github.com/Juneo-io/juneogo/ids" 7 | 8 | // Fx wraps an instance of a feature extension 9 | type Fx struct { 10 | ID ids.ID 11 | Fx interface{} 12 | } 13 | -------------------------------------------------------------------------------- /snow/engine/common/halter.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package common 5 | 6 | import ( 7 | "context" 8 | "sync/atomic" 9 | ) 10 | 11 | var _ Haltable = (*Halter)(nil) 12 | 13 | type Haltable interface { 14 | Halt(context.Context) 15 | Halted() bool 16 | } 17 | 18 | type Halter struct { 19 | halted uint32 20 | } 21 | 22 | func (h *Halter) Halt(context.Context) { 23 | atomic.StoreUint32(&h.halted, 1) 24 | } 25 | 26 | func (h *Halter) Halted() bool { 27 | return atomic.LoadUint32(&h.halted) == 1 28 | } 29 | -------------------------------------------------------------------------------- /snow/engine/common/request.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/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 []byte(fmt.Sprintf("%s:%d", r.NodeID, r.RequestID)), nil 19 | } 20 | -------------------------------------------------------------------------------- /snow/engine/common/request_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /snow/engine/common/state_syncer.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /snow/engine/common/test_bootstrapper.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package common 5 | 6 | import ( 7 | "context" 8 | "errors" 9 | 10 | "github.com/stretchr/testify/require" 11 | ) 12 | 13 | var ( 14 | _ BootstrapableEngine = (*BootstrapperTest)(nil) 15 | 16 | errClear = errors.New("unexpectedly called Clear") 17 | ) 18 | 19 | type BootstrapperTest struct { 20 | EngineTest 21 | 22 | CantClear bool 23 | 24 | ClearF func(ctx context.Context) error 25 | } 26 | 27 | func (b *BootstrapperTest) Default(cant bool) { 28 | b.EngineTest.Default(cant) 29 | 30 | b.CantClear = cant 31 | } 32 | 33 | func (b *BootstrapperTest) Clear(ctx context.Context) error { 34 | if b.ClearF != nil { 35 | return b.ClearF(ctx) 36 | } 37 | if b.CantClear && b.T != nil { 38 | require.FailNow(b.T, errClear.Error()) 39 | } 40 | return errClear 41 | } 42 | -------------------------------------------------------------------------------- /snow/engine/common/test_timer.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package common 5 | 6 | import ( 7 | "testing" 8 | "time" 9 | 10 | "github.com/stretchr/testify/require" 11 | ) 12 | 13 | var _ Timer = (*TimerTest)(nil) 14 | 15 | // TimerTest is a test timer 16 | type TimerTest struct { 17 | T *testing.T 18 | 19 | CantRegisterTimout bool 20 | 21 | RegisterTimeoutF func(time.Duration) 22 | } 23 | 24 | // Default set the default callable value to [cant] 25 | func (t *TimerTest) Default(cant bool) { 26 | t.CantRegisterTimout = cant 27 | } 28 | 29 | func (t *TimerTest) RegisterTimeout(delay time.Duration) { 30 | if t.RegisterTimeoutF != nil { 31 | t.RegisterTimeoutF(delay) 32 | } else if t.CantRegisterTimout && t.T != nil { 33 | require.FailNow(t.T, "Unexpectedly called RegisterTimeout") 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /snow/engine/common/timer.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package common 5 | 6 | import "time" 7 | 8 | // Timer describes the standard interface for specifying a timeout 9 | type Timer interface { 10 | // RegisterTimeout specifies how much time to delay the next timeout message 11 | // by. If the supernet has been bootstrapped, the timeout will fire 12 | // immediately. 13 | RegisterTimeout(time.Duration) 14 | } 15 | -------------------------------------------------------------------------------- /snow/engine/common/traced_state_syncer.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /snow/engine/snowman/block/state_summary.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package block 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/Juneo-io/juneogo/ids" 10 | ) 11 | 12 | // StateSummary represents all the information needed to download, verify, and 13 | // rebuild its state. 14 | type StateSummary interface { 15 | // ID uniquely identifies this state summary, regardless of the chain state. 16 | ID() ids.ID 17 | 18 | // Height uniquely identifies this an accepted state summary. 19 | Height() uint64 20 | 21 | // Bytes returns a byte slice than can be used to reconstruct this summary. 22 | Bytes() []byte 23 | 24 | // Accept triggers the VM to start state syncing to this summary. 25 | // 26 | // It returns the state sync mode selected by the VM. 27 | Accept(context.Context) (StateSyncMode, error) 28 | } 29 | -------------------------------------------------------------------------------- /snow/event/blockable.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package event 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/Juneo-io/juneogo/ids" 10 | "github.com/Juneo-io/juneogo/utils/set" 11 | ) 12 | 13 | // Blockable defines what an object must implement to be able to block on 14 | // dependent events being completed. 15 | type Blockable interface { 16 | // IDs that this object is blocking on 17 | Dependencies() set.Set[ids.ID] 18 | // Notify this object that an event has been fulfilled 19 | Fulfill(context.Context, ids.ID) 20 | // Notify this object that an event has been abandoned 21 | Abandon(context.Context, ids.ID) 22 | // Update the state of this object without changing the status of any events 23 | Update(context.Context) 24 | } 25 | -------------------------------------------------------------------------------- /snow/networking/benchlist/benchable.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package benchlist 5 | 6 | import "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /snow/networking/handler/parser.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package handler 5 | 6 | import ( 7 | "github.com/Juneo-io/juneogo/ids" 8 | "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /snow/networking/router/main_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/sender/external_sender.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package sender 5 | 6 | import ( 7 | "github.com/Juneo-io/juneogo/ids" 8 | "github.com/Juneo-io/juneogo/message" 9 | "github.com/Juneo-io/juneogo/snow/engine/common" 10 | "github.com/Juneo-io/juneogo/supernets" 11 | "github.com/Juneo-io/juneogo/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 | supernetID ids.ID, 21 | allower supernets.Allower, 22 | ) set.Set[ids.NodeID] 23 | } 24 | -------------------------------------------------------------------------------- /snow/networking/timeout/main_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/state.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /snow/uptime/no_op_calculator.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/ids" 10 | ) 11 | 12 | var NoOpCalculator Calculator = noOpCalculator{} 13 | 14 | type noOpCalculator struct{} 15 | 16 | func (noOpCalculator) CalculateUptime(ids.NodeID, ids.ID) (time.Duration, time.Time, error) { 17 | return 0, time.Time{}, nil 18 | } 19 | 20 | func (noOpCalculator) CalculateUptimePercent(ids.NodeID, ids.ID) (float64, error) { 21 | return 0, nil 22 | } 23 | 24 | func (noOpCalculator) CalculateUptimePercentFrom(ids.NodeID, ids.ID, time.Time) (float64, error) { 25 | return 0, nil 26 | } 27 | -------------------------------------------------------------------------------- /snow/validators/connector.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/ids" 10 | "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /snow/validators/subnet_connector.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/ids" 10 | ) 11 | 12 | // SupernetConnector represents a handler that is called when a connection is 13 | // marked as connected to a supernet 14 | type SupernetConnector interface { 15 | ConnectedSupernet(ctx context.Context, nodeID ids.NodeID, supernetID ids.ID) error 16 | } 17 | -------------------------------------------------------------------------------- /snow/validators/unhandled_subnet_connector.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package validators 5 | 6 | import ( 7 | "context" 8 | "fmt" 9 | 10 | "github.com/Juneo-io/juneogo/ids" 11 | ) 12 | 13 | var UnhandledSupernetConnector SupernetConnector = &unhandledSupernetConnector{} 14 | 15 | type unhandledSupernetConnector struct{} 16 | 17 | func (unhandledSupernetConnector) ConnectedSupernet(_ context.Context, nodeID ids.NodeID, supernetID ids.ID) error { 18 | return fmt.Errorf( 19 | "unhandled ConnectedSupernet with nodeID=%q and supernetID=%q", 20 | nodeID, 21 | supernetID, 22 | ) 23 | } 24 | -------------------------------------------------------------------------------- /staking/certificate.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /staking/large_rsa_key.cert: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Juneo-io/juneogo/494e542f7120bcfbd69caf9e586c2f0d737af939/staking/large_rsa_key.cert -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /staking/parse_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package staking 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/stretchr/testify/require" 10 | 11 | _ "embed" 12 | ) 13 | 14 | //go:embed large_rsa_key.cert 15 | var largeRSAKeyCert []byte 16 | 17 | func TestParseCheckLargeCert(t *testing.T) { 18 | _, err := ParseCertificate(largeRSAKeyCert) 19 | require.ErrorIs(t, err, ErrCertificateTooLarge) 20 | } 21 | 22 | func BenchmarkParse(b *testing.B) { 23 | tlsCert, err := NewTLSCert() 24 | require.NoError(b, err) 25 | 26 | bytes := tlsCert.Leaf.Raw 27 | 28 | b.ResetTimer() 29 | for i := 0; i < b.N; i++ { 30 | _, err = ParseCertificate(bytes) 31 | require.NoError(b, err) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /staking/tls_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package staking 5 | 6 | import ( 7 | "crypto" 8 | "crypto/rand" 9 | "fmt" 10 | "testing" 11 | "time" 12 | 13 | "github.com/stretchr/testify/require" 14 | 15 | "github.com/Juneo-io/juneogo/utils/hashing" 16 | ) 17 | 18 | func TestMakeKeys(t *testing.T) { 19 | require := require.New(t) 20 | 21 | cert, err := NewTLSCert() 22 | require.NoError(err) 23 | 24 | msg := []byte(fmt.Sprintf("msg %d", time.Now().Unix())) 25 | msgHash := hashing.ComputeHash256(msg) 26 | 27 | sig, err := cert.PrivateKey.(crypto.Signer).Sign(rand.Reader, msgHash, crypto.SHA256) 28 | require.NoError(err) 29 | 30 | require.NoError(cert.Leaf.CheckSignature(cert.Leaf.SignatureAlgorithm, msg, sig)) 31 | } 32 | -------------------------------------------------------------------------------- /supernets/no_op_allower.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package supernets 5 | 6 | import "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /trace/noop.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /utils/atomic.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package utils 5 | 6 | import "sync" 7 | 8 | type Atomic[T any] struct { 9 | lock sync.RWMutex 10 | value T 11 | } 12 | 13 | func (a *Atomic[T]) Get() T { 14 | a.lock.RLock() 15 | defer a.lock.RUnlock() 16 | 17 | return a.value 18 | } 19 | 20 | func (a *Atomic[T]) Set(value T) { 21 | a.lock.Lock() 22 | defer a.lock.Unlock() 23 | 24 | a.value = value 25 | } 26 | -------------------------------------------------------------------------------- /utils/atomic_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package utils 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/stretchr/testify/require" 10 | ) 11 | 12 | func TestAtomic(t *testing.T) { 13 | require := require.New(t) 14 | 15 | var a Atomic[bool] 16 | require.Zero(a.Get()) 17 | 18 | a.Set(false) 19 | require.False(a.Get()) 20 | 21 | a.Set(true) 22 | require.True(a.Get()) 23 | 24 | a.Set(false) 25 | require.False(a.Get()) 26 | } 27 | -------------------------------------------------------------------------------- /utils/beacon/beacon.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package beacon 5 | 6 | import ( 7 | "github.com/Juneo-io/juneogo/ids" 8 | "github.com/Juneo-io/juneogo/utils/ips" 9 | ) 10 | 11 | var _ Beacon = (*beacon)(nil) 12 | 13 | type Beacon interface { 14 | ID() ids.NodeID 15 | IP() ips.IPPort 16 | } 17 | 18 | type beacon struct { 19 | id ids.NodeID 20 | ip ips.IPPort 21 | } 22 | 23 | func New(id ids.NodeID, ip ips.IPPort) Beacon { 24 | return &beacon{ 25 | id: id, 26 | ip: ip, 27 | } 28 | } 29 | 30 | func (b *beacon) ID() ids.NodeID { 31 | return b.id 32 | } 33 | 34 | func (b *beacon) IP() ips.IPPort { 35 | return b.ip 36 | } 37 | -------------------------------------------------------------------------------- /utils/bloom/hasher.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /utils/bloom/hasher_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/ids" 12 | "github.com/Juneo-io/juneogo/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/compression/compressor.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package compression 5 | 6 | // Compressor compresss 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 | -------------------------------------------------------------------------------- /utils/compression/no_compressor.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/compression/no_compressor_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/compression/zstd_zip_bomb.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Juneo-io/juneogo/494e542f7120bcfbd69caf9e586c2f0d737af939/utils/compression/zstd_zip_bomb.bin -------------------------------------------------------------------------------- /utils/constants/aliases.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/constants/application.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 = "juneomcn" 10 | 11 | // AppName exports the name of the avalanche application 12 | AppName = "juneogo" 13 | ) 14 | -------------------------------------------------------------------------------- /utils/constants/memory.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /utils/constants/vm_ids.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package constants 5 | 6 | import "github.com/Juneo-io/juneogo/ids" 7 | 8 | var ( 9 | PlatformVMID = ids.ID{'p', 'l', 'a', 't', 'f', 'o', 'r', 'm', 'v', 'm'} 10 | AVMID = ids.ID{'j', 'v', 'm'} 11 | EVMID = ids.ID{'j', 'e', 'v', 'm'} 12 | ) 13 | -------------------------------------------------------------------------------- /utils/crypto/keychain/ledger.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package keychain 5 | 6 | import ( 7 | "github.com/Juneo-io/juneogo/ids" 8 | "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /utils/crypto/secp256k1/secp256k1_benchmark_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/utils" 12 | "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /utils/crypto/secp256k1/test_keys.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package secp256k1 5 | 6 | import "github.com/Juneo-io/juneogo/utils/cb58" 7 | 8 | func TestKeys() []*PrivateKey { 9 | var ( 10 | keyStrings = []string{ 11 | "24jUJ9vZexUM6expyMcT48LBx27k1m7xpraoV62oSQAHdziao5", 12 | "2MMvUMsxx6zsHSNXJdFD8yc5XkancvwyKPwpw4xUK3TCGDuNBY", 13 | "cxb7KpGWhDMALTjNNSJ7UQkkomPesyWAPUaWRGdyeBNzR6f35", 14 | "ewoqjP7PxY4yr3iLTpLisriqt94hdyDFNgchSxGGztUrTXtNN", 15 | "2RWLv6YVEXDiWLpaCbXhhqxtLbnFaKQsWPSSMSPhpWo47uJAeV", 16 | } 17 | keys = make([]*PrivateKey, len(keyStrings)) 18 | ) 19 | 20 | for i, key := range keyStrings { 21 | privKeyBytes, err := cb58.Decode(key) 22 | if err != nil { 23 | panic(err) 24 | } 25 | 26 | keys[i], err = ToPrivateKey(privKeyBytes) 27 | if err != nil { 28 | panic(err) 29 | } 30 | } 31 | return keys 32 | } 33 | -------------------------------------------------------------------------------- /utils/dynamicip/no_updater.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package dynamicip 5 | 6 | import "github.com/Juneo-io/juneogo/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/error.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package utils 5 | 6 | func Err(errors ...error) error { 7 | for _, err := range errors { 8 | if err != nil { 9 | return err 10 | } 11 | } 12 | return nil 13 | } 14 | -------------------------------------------------------------------------------- /utils/filesystem/io.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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-2024, 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 | -------------------------------------------------------------------------------- /utils/filesystem/rename.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /utils/filesystem/rename_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package filesystem 5 | 6 | import ( 7 | "os" 8 | "testing" 9 | 10 | "github.com/stretchr/testify/require" 11 | ) 12 | 13 | func TestRenameIfExists(t *testing.T) { 14 | require := require.New(t) 15 | 16 | t.Parallel() 17 | 18 | f, err := os.CreateTemp(os.TempDir(), "test-rename") 19 | require.NoError(err) 20 | 21 | a := f.Name() 22 | b := a + ".2" 23 | 24 | require.NoError(f.Close()) 25 | 26 | // rename "a" to "b" 27 | renamed, err := RenameIfExists(a, b) 28 | require.NoError(err) 29 | require.True(renamed) 30 | 31 | // rename "b" to "a" 32 | renamed, err = RenameIfExists(b, a) 33 | require.NoError(err) 34 | require.True(renamed) 35 | 36 | // remove "a", but rename "a"->"b" should NOT error 37 | require.NoError(os.RemoveAll(a)) 38 | renamed, err = RenameIfExists(a, b) 39 | require.NoError(err) 40 | require.False(renamed) 41 | } 42 | -------------------------------------------------------------------------------- /utils/formatting/address/converter.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package address 5 | 6 | import "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /utils/formatting/int_format.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /utils/formatting/int_format_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /utils/formatting/prefixed_stringer.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /utils/hashing/consistent/hashable.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/hashing/hasher.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /utils/ips/lookup.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package ips 5 | 6 | import ( 7 | "errors" 8 | "net" 9 | ) 10 | 11 | var errNoIPsFound = errors.New("no IPs found") 12 | 13 | // Lookup attempts to resolve a hostname to a single IP. If multiple IPs are 14 | // found, then lookup will attempt to return an IPv4 address, otherwise it will 15 | // pick any of the IPs. 16 | // 17 | // Note: IPv4 is preferred because `net.Listen` prefers IPv4. 18 | func Lookup(hostname string) (net.IP, error) { 19 | ips, err := net.LookupIP(hostname) 20 | if err != nil { 21 | return nil, err 22 | } 23 | if len(ips) == 0 { 24 | return nil, errNoIPsFound 25 | } 26 | 27 | for _, ip := range ips { 28 | ipv4 := ip.To4() 29 | if ipv4 != nil { 30 | return ipv4, nil 31 | } 32 | } 33 | return ips[0], nil 34 | } 35 | -------------------------------------------------------------------------------- /utils/ips/lookup_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package ips 5 | 6 | import ( 7 | "net" 8 | "testing" 9 | 10 | "github.com/stretchr/testify/require" 11 | ) 12 | 13 | func TestLookup(t *testing.T) { 14 | tests := []struct { 15 | host string 16 | ip net.IP 17 | }{ 18 | { 19 | host: "127.0.0.1", 20 | ip: net.ParseIP("127.0.0.1").To4(), 21 | }, 22 | { 23 | host: "localhost", 24 | ip: net.ParseIP("127.0.0.1").To4(), 25 | }, 26 | { 27 | host: "::", 28 | ip: net.IPv6zero, 29 | }, 30 | { 31 | host: "0.0.0.0", 32 | ip: net.ParseIP("0.0.0.0").To4(), 33 | }, 34 | } 35 | for _, tt := range tests { 36 | t.Run(tt.host, func(t *testing.T) { 37 | require := require.New(t) 38 | 39 | ip, err := Lookup(tt.host) 40 | require.NoError(err) 41 | require.Equal(tt.ip, ip) 42 | }) 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /utils/json/float32.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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-2024, 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 | -------------------------------------------------------------------------------- /utils/json/uint16.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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-2024, 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-2024, 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 | -------------------------------------------------------------------------------- /utils/json/uint8.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/logging/config.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/logging/log_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package logging 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/stretchr/testify/require" 10 | ) 11 | 12 | func TestLog(t *testing.T) { 13 | log := NewLogger("", NewWrappedCore(Info, Discard, Plain.ConsoleEncoder())) 14 | 15 | recovered := new(bool) 16 | panicFunc := func() { 17 | panic("DON'T PANIC!") 18 | } 19 | exitFunc := func() { 20 | *recovered = true 21 | } 22 | log.RecoverAndExit(panicFunc, exitFunc) 23 | 24 | require.True(t, *recovered) 25 | } 26 | -------------------------------------------------------------------------------- /utils/math/averager.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /utils/math/continuous_averager_benchmark_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /utils/math/meter/factory.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /utils/math/sync_averager.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/metric/namespace.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package metric 5 | 6 | import "strings" 7 | 8 | func AppendNamespace(prefix, suffix string) string { 9 | switch { 10 | case len(prefix) == 0: 11 | return suffix 12 | case len(suffix) == 0: 13 | return prefix 14 | default: 15 | return strings.Join([]string{prefix, suffix}, "_") 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /utils/password/hash_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/perms/chmod.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /utils/perms/create.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /utils/perms/perms.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /utils/resource/no_usage.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /utils/sampler/uniform.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package sampler 5 | 6 | // Uniform samples values without replacement in the provided range 7 | type Uniform interface { 8 | Initialize(sampleRange uint64) 9 | // Sample returns length numbers in the range [0,sampleRange). If there 10 | // aren't enough numbers in the range, an error is returned. If length is 11 | // negative the implementation may panic. 12 | Sample(length int) ([]uint64, error) 13 | 14 | Reset() 15 | Next() (uint64, error) 16 | } 17 | 18 | // NewUniform returns a new sampler 19 | func NewUniform() Uniform { 20 | return &uniformReplacer{ 21 | rng: globalRNG, 22 | } 23 | } 24 | 25 | // NewDeterministicUniform returns a new sampler 26 | func NewDeterministicUniform(source Source) Uniform { 27 | return &uniformReplacer{ 28 | rng: &rng{ 29 | rng: source, 30 | }, 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /utils/sampler/uniform_benchmark_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | // BenchmarkAllUniform 12 | func BenchmarkAllUniform(b *testing.B) { 13 | sizes := []uint64{ 14 | 30, 15 | 35, 16 | 500, 17 | 10000, 18 | 100000, 19 | } 20 | for _, s := range uniformSamplers { 21 | for _, size := range sizes { 22 | b.Run(fmt.Sprintf("sampler %s with %d elements uniformly", s.name, size), func(b *testing.B) { 23 | UniformBenchmark(b, s.sampler, size, 30) 24 | }) 25 | } 26 | } 27 | } 28 | 29 | func UniformBenchmark(b *testing.B, s Uniform, size uint64, toSample int) { 30 | s.Initialize(size) 31 | 32 | b.ResetTimer() 33 | for i := 0; i < b.N; i++ { 34 | _, _ = s.Sample(toSample) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /utils/sampler/weighted.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package sampler 5 | 6 | import "errors" 7 | 8 | var ErrOutOfRange = errors.New("out of range") 9 | 10 | // Weighted defines how to sample a specified valued based on a provided 11 | // weighted distribution 12 | type Weighted interface { 13 | Initialize(weights []uint64) error 14 | Sample(sampleValue uint64) (int, error) 15 | } 16 | 17 | // NewWeighted returns a new sampler 18 | func NewWeighted() Weighted { 19 | return &weightedBest{ 20 | samplers: []Weighted{ 21 | &weightedArray{}, 22 | &weightedHeap{}, 23 | &weightedUniform{ 24 | maxWeight: 1024, 25 | }, 26 | }, 27 | benchmarkIterations: 100, 28 | } 29 | } 30 | 31 | func NewDeterministicWeighted() Weighted { 32 | return &weightedHeap{} 33 | } 34 | -------------------------------------------------------------------------------- /utils/set/set_benchmark_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package set 5 | 6 | import ( 7 | "strconv" 8 | "testing" 9 | ) 10 | 11 | func BenchmarkSetList(b *testing.B) { 12 | sizes := []int{5, 25, 100, 100_000} // Test with various sizes 13 | for size := range sizes { 14 | b.Run(strconv.Itoa(size), func(b *testing.B) { 15 | set := Set[int]{} 16 | for i := 0; i < size; i++ { 17 | set.Add(i) 18 | } 19 | b.ResetTimer() 20 | for n := 0; n < b.N; n++ { 21 | set.List() 22 | } 23 | }) 24 | } 25 | } 26 | 27 | func BenchmarkSetClear(b *testing.B) { 28 | for _, numElts := range []int{10, 25, 50, 100, 250, 500, 1000} { 29 | b.Run(strconv.Itoa(numElts), func(b *testing.B) { 30 | set := NewSet[int](numElts) 31 | for n := 0; n < b.N; n++ { 32 | for i := 0; i < numElts; i++ { 33 | set.Add(i) 34 | } 35 | set.Clear() 36 | } 37 | }) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /utils/stacktrace.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /utils/storage/storage_unix.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 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 | -------------------------------------------------------------------------------- /utils/timer/meter.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /utils/timer/timer_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /utils/ulimit/ulimit_windows.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/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(max uint64, log logging.Logger) error { 15 | if max != DefaultFDLimit { 16 | log.Warn("fd-limit is not supported for windows") 17 | } 18 | return nil 19 | } 20 | -------------------------------------------------------------------------------- /utils/units/avax.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/units/bytes.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /utils/wrappers/closers.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package wrappers 5 | 6 | import ( 7 | "io" 8 | "sync" 9 | ) 10 | 11 | // Closer is a nice utility for closing a group of objects while reporting an 12 | // error if one occurs. 13 | type Closer struct { 14 | lock sync.Mutex 15 | closers []io.Closer 16 | } 17 | 18 | // Add a new object to be closed. 19 | func (c *Closer) Add(closer io.Closer) { 20 | c.lock.Lock() 21 | defer c.lock.Unlock() 22 | 23 | c.closers = append(c.closers, closer) 24 | } 25 | 26 | // Close closes each of the closers add to [c] and returns the first error 27 | // that occurs or nil if no error occurs. 28 | func (c *Closer) Close() error { 29 | c.lock.Lock() 30 | closers := c.closers 31 | c.closers = nil 32 | c.lock.Unlock() 33 | 34 | errs := Errs{} 35 | for _, closer := range closers { 36 | errs.Add(closer.Close()) 37 | } 38 | return errs.Err 39 | } 40 | -------------------------------------------------------------------------------- /utils/wrappers/errors.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /utils/zero.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 *new(T) 9 | } 10 | 11 | // ZeroSlice sets all values of the provided slice to the type's zero value. 12 | // 13 | // This can be useful to ensure that the garbage collector doesn't hold 14 | // references to values that are no longer desired. 15 | func ZeroSlice[T any](s []T) { 16 | for i := range s { 17 | s[i] = *new(T) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /version/compatibility.json: -------------------------------------------------------------------------------- 1 | { 2 | "35": ["v1.0.0"] 3 | } 4 | -------------------------------------------------------------------------------- /version/constants_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /version/string.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package version 5 | 6 | import ( 7 | "fmt" 8 | "runtime" 9 | "strings" 10 | ) 11 | 12 | var ( 13 | // String is displayed when CLI arg --version is used 14 | String string 15 | 16 | // GitCommit is set in the build script at compile time 17 | GitCommit string 18 | ) 19 | 20 | func init() { 21 | format := "%s [database=%s, rpcchainvm=%d" 22 | args := []interface{}{ 23 | CurrentApp, 24 | CurrentDatabase, 25 | RPCChainVMProtocol, 26 | } 27 | if GitCommit != "" { 28 | format += ", commit=%s" 29 | args = append(args, GitCommit) 30 | } 31 | 32 | // add golang version 33 | goVersion := runtime.Version() 34 | goVersionNumber := strings.TrimPrefix(goVersion, "go") 35 | format += ", go=%s" 36 | args = append(args, goVersionNumber) 37 | 38 | format += "]\n" 39 | String = fmt.Sprintf(format, args...) 40 | } 41 | -------------------------------------------------------------------------------- /version/version_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/block/block.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package block 5 | 6 | import ( 7 | "time" 8 | 9 | "github.com/Juneo-io/juneogo/codec" 10 | "github.com/Juneo-io/juneogo/ids" 11 | "github.com/Juneo-io/juneogo/snow" 12 | "github.com/Juneo-io/juneogo/vms/avm/txs" 13 | ) 14 | 15 | // Block defines the common stateless interface for all blocks 16 | type Block interface { 17 | snow.ContextInitializable 18 | 19 | ID() ids.ID 20 | Parent() ids.ID 21 | Height() uint64 22 | // Timestamp that this block was created at 23 | Timestamp() time.Time 24 | MerkleRoot() ids.ID 25 | Bytes() []byte 26 | 27 | // Txs returns the transactions contained in the block 28 | Txs() []*txs.Tx 29 | 30 | // note: initialize does not assume that the transactions are initialized, 31 | // and initializes them itself. 32 | initialize(bytes []byte, cm codec.Manager) error 33 | } 34 | -------------------------------------------------------------------------------- /vms/avm/config.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/vms/avm/network" 10 | ) 11 | 12 | var DefaultConfig = Config{ 13 | Network: network.DefaultConfig, 14 | IndexTransactions: false, 15 | IndexAllowIncomplete: false, 16 | ChecksumsEnabled: false, 17 | } 18 | 19 | type Config struct { 20 | Network network.Config `json:"network"` 21 | IndexTransactions bool `json:"index-transactions"` 22 | IndexAllowIncomplete bool `json:"index-allow-incomplete"` 23 | ChecksumsEnabled bool `json:"checksums-enabled"` 24 | } 25 | 26 | func ParseConfig(configBytes []byte) (Config, error) { 27 | if len(configBytes) == 0 { 28 | return DefaultConfig, nil 29 | } 30 | 31 | config := DefaultConfig 32 | err := json.Unmarshal(configBytes, &config) 33 | return config, err 34 | } 35 | -------------------------------------------------------------------------------- /vms/avm/config/config.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package config 5 | 6 | import "time" 7 | 8 | // Struct collecting all the foundational parameters of the AVM 9 | type Config struct { 10 | // Fee that is burned by every non-asset creating transaction 11 | TxFee uint64 12 | 13 | // Fee that must be burned by every asset creating transaction 14 | CreateAssetTxFee uint64 15 | 16 | // Time of the E network upgrade 17 | EUpgradeTime time.Time 18 | } 19 | 20 | func (c *Config) IsEActivated(timestamp time.Time) bool { 21 | return !timestamp.Before(c.EUpgradeTime) 22 | } 23 | -------------------------------------------------------------------------------- /vms/avm/factory.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package avm 5 | 6 | import ( 7 | "github.com/Juneo-io/juneogo/utils/logging" 8 | "github.com/Juneo-io/juneogo/vms" 9 | "github.com/Juneo-io/juneogo/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/avm/genesis.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package avm 5 | 6 | import ( 7 | "cmp" 8 | 9 | "github.com/Juneo-io/juneogo/utils" 10 | "github.com/Juneo-io/juneogo/vms/avm/txs" 11 | ) 12 | 13 | var _ utils.Sortable[*GenesisAsset] = (*GenesisAsset)(nil) 14 | 15 | type Genesis struct { 16 | Txs []*GenesisAsset `serialize:"true"` 17 | } 18 | 19 | type GenesisAsset struct { 20 | Alias string `serialize:"true"` 21 | txs.CreateAssetTx `serialize:"true"` 22 | } 23 | 24 | func (g *GenesisAsset) Compare(other *GenesisAsset) int { 25 | return cmp.Compare(g.Alias, other.Alias) 26 | } 27 | -------------------------------------------------------------------------------- /vms/avm/genesis_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package avm 5 | 6 | import ( 7 | "fmt" 8 | "testing" 9 | 10 | "github.com/stretchr/testify/require" 11 | ) 12 | 13 | func TestGenesisAssetCompare(t *testing.T) { 14 | tests := []struct { 15 | a *GenesisAsset 16 | b *GenesisAsset 17 | expected int 18 | }{ 19 | { 20 | a: &GenesisAsset{}, 21 | b: &GenesisAsset{}, 22 | expected: 0, 23 | }, 24 | { 25 | a: &GenesisAsset{ 26 | Alias: "a", 27 | }, 28 | b: &GenesisAsset{ 29 | Alias: "aa", 30 | }, 31 | expected: -1, 32 | }, 33 | } 34 | for _, test := range tests { 35 | t.Run(fmt.Sprintf("%s_%s_%d", test.a.Alias, test.b.Alias, test.expected), func(t *testing.T) { 36 | require := require.New(t) 37 | 38 | require.Equal(test.expected, test.a.Compare(test.b)) 39 | require.Equal(-test.expected, test.b.Compare(test.a)) 40 | }) 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /vms/avm/health.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/avm/network/tx_verifier.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package network 5 | 6 | import ( 7 | "sync" 8 | 9 | "github.com/Juneo-io/juneogo/vms/avm/txs" 10 | ) 11 | 12 | var _ TxVerifier = (*LockedTxVerifier)(nil) 13 | 14 | type TxVerifier interface { 15 | // VerifyTx verifies that the transaction should be issued into the mempool. 16 | VerifyTx(tx *txs.Tx) error 17 | } 18 | 19 | type LockedTxVerifier struct { 20 | lock sync.Locker 21 | txVerifier TxVerifier 22 | } 23 | 24 | func (l *LockedTxVerifier) VerifyTx(tx *txs.Tx) error { 25 | l.lock.Lock() 26 | defer l.lock.Unlock() 27 | 28 | return l.txVerifier.VerifyTx(tx) 29 | } 30 | 31 | func NewLockedTxVerifier(lock sync.Locker, txVerifier TxVerifier) *LockedTxVerifier { 32 | return &LockedTxVerifier{ 33 | lock: lock, 34 | txVerifier: txVerifier, 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /vms/avm/state/versions.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package state 5 | 6 | import "github.com/Juneo-io/juneogo/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/avm/txs/executor/backend.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/codec" 10 | "github.com/Juneo-io/juneogo/ids" 11 | "github.com/Juneo-io/juneogo/snow" 12 | "github.com/Juneo-io/juneogo/vms/avm/config" 13 | "github.com/Juneo-io/juneogo/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.JUNEAssetID if this AVM is 23 | // running in a supernet. 24 | FeeAssetID ids.ID 25 | Bootstrapped bool 26 | } 27 | -------------------------------------------------------------------------------- /vms/components/avax/asset.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/ids" 10 | "github.com/Juneo-io/juneogo/vms/components/verify" 11 | ) 12 | 13 | var ( 14 | errNilAssetID = errors.New("nil asset ID is not valid") 15 | errEmptyAssetID = errors.New("empty asset ID is not valid") 16 | 17 | _ verify.Verifiable = (*Asset)(nil) 18 | ) 19 | 20 | type Asset struct { 21 | ID ids.ID `serialize:"true" json:"assetID"` 22 | } 23 | 24 | // AssetID returns the ID of the contained asset 25 | func (asset *Asset) AssetID() ids.ID { 26 | return asset.ID 27 | } 28 | 29 | func (asset *Asset) Verify() error { 30 | switch { 31 | case asset == nil: 32 | return errNilAssetID 33 | case asset.ID == ids.Empty: 34 | return errEmptyAssetID 35 | default: 36 | return nil 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /vms/components/avax/metadata_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package avax 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/stretchr/testify/require" 10 | ) 11 | 12 | func TestMetaDataVerifyNil(t *testing.T) { 13 | md := (*Metadata)(nil) 14 | err := md.Verify() 15 | require.ErrorIs(t, err, errNilMetadata) 16 | } 17 | 18 | func TestMetaDataVerifyUninitialized(t *testing.T) { 19 | md := &Metadata{} 20 | err := md.Verify() 21 | require.ErrorIs(t, err, errMetadataNotInitialize) 22 | } 23 | -------------------------------------------------------------------------------- /vms/components/avax/state.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/components/avax/utxo.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/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/components/avax/utxo_handler.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package avax 5 | 6 | import "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /vms/components/index/metrics.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package index 5 | 6 | import "github.com/prometheus/client_golang/prometheus" 7 | 8 | type metrics struct { 9 | numTxsIndexed prometheus.Counter 10 | } 11 | 12 | func (m *metrics) initialize(namespace string, registerer prometheus.Registerer) error { 13 | m.numTxsIndexed = prometheus.NewCounter(prometheus.CounterOpts{ 14 | Namespace: namespace, 15 | Name: "txs_indexed", 16 | Help: "Number of transactions indexed", 17 | }) 18 | return registerer.Register(m.numTxsIndexed) 19 | } 20 | -------------------------------------------------------------------------------- /vms/components/keystore/codec.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package keystore 5 | 6 | import ( 7 | "math" 8 | 9 | "github.com/Juneo-io/juneogo/codec" 10 | "github.com/Juneo-io/juneogo/codec/linearcodec" 11 | "github.com/Juneo-io/juneogo/utils" 12 | ) 13 | 14 | const CodecVersion = 0 15 | 16 | var ( 17 | Codec codec.Manager 18 | LegacyCodec codec.Manager 19 | ) 20 | 21 | func init() { 22 | c := linearcodec.NewDefault() 23 | Codec = codec.NewDefaultManager() 24 | lc := linearcodec.NewDefault() 25 | LegacyCodec = codec.NewManager(math.MaxInt32) 26 | 27 | err := utils.Err( 28 | Codec.RegisterCodec(CodecVersion, c), 29 | LegacyCodec.RegisterCodec(CodecVersion, lc), 30 | ) 31 | if err != nil { 32 | panic(err) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /vms/components/verify/verification.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package verify 5 | 6 | import "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /vms/components/verify/verification_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/example/xsvm/block/codec.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package block 5 | 6 | import "github.com/Juneo-io/juneogo/vms/example/xsvm/tx" 7 | 8 | const CodecVersion = tx.CodecVersion 9 | 10 | var Codec = tx.Codec 11 | -------------------------------------------------------------------------------- /vms/example/xsvm/cmd/chain/cmd.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/vms/example/xsvm/cmd/chain/create" 10 | "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /vms/example/xsvm/cmd/issue/cmd.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/vms/example/xsvm/cmd/issue/export" 10 | "github.com/Juneo-io/juneogo/vms/example/xsvm/cmd/issue/importtx" 11 | "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /vms/example/xsvm/cmd/issue/status/status.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/ids" 12 | "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /vms/example/xsvm/cmd/run/cmd.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/vms/example/xsvm" 12 | "github.com/Juneo-io/juneogo/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/cmd/version/cmd.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/version" 12 | "github.com/Juneo-io/juneogo/vms/example/xsvm" 13 | ) 14 | 15 | const format = `%s: 16 | VMID: %s 17 | Version: %s 18 | Plugin Version: %d 19 | ` 20 | 21 | func Command() *cobra.Command { 22 | return &cobra.Command{ 23 | Use: "version", 24 | Short: "Prints out the version", 25 | RunE: versionFunc, 26 | } 27 | } 28 | 29 | func versionFunc(*cobra.Command, []string) error { 30 | fmt.Printf( 31 | format, 32 | xsvm.Name, 33 | xsvm.ID, 34 | xsvm.Version, 35 | version.RPCChainVMProtocol, 36 | ) 37 | return nil 38 | } 39 | -------------------------------------------------------------------------------- /vms/example/xsvm/cmd/xsvm/main.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package main 5 | 6 | import ( 7 | "context" 8 | "fmt" 9 | "os" 10 | 11 | "github.com/spf13/cobra" 12 | 13 | "github.com/Juneo-io/juneogo/vms/example/xsvm/cmd/account" 14 | "github.com/Juneo-io/juneogo/vms/example/xsvm/cmd/chain" 15 | "github.com/Juneo-io/juneogo/vms/example/xsvm/cmd/issue" 16 | "github.com/Juneo-io/juneogo/vms/example/xsvm/cmd/run" 17 | "github.com/Juneo-io/juneogo/vms/example/xsvm/cmd/version" 18 | ) 19 | 20 | func init() { 21 | cobra.EnablePrefixMatching = true 22 | } 23 | 24 | func main() { 25 | cmd := run.Command() 26 | cmd.AddCommand( 27 | account.Command(), 28 | chain.Command(), 29 | issue.Command(), 30 | version.Command(), 31 | ) 32 | ctx := context.Background() 33 | if err := cmd.ExecuteContext(ctx); err != nil { 34 | fmt.Fprintf(os.Stderr, "command failed %v\n", err) 35 | os.Exit(1) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /vms/example/xsvm/constants.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package xsvm 5 | 6 | import ( 7 | "github.com/Juneo-io/juneogo/ids" 8 | "github.com/Juneo-io/juneogo/version" 9 | ) 10 | 11 | const Name = "xsvm" 12 | 13 | var ( 14 | ID = ids.ID{'x', 's', 'v', 'm'} 15 | 16 | Version = &version.Semantic{ 17 | Major: 1, 18 | Minor: 0, 19 | Patch: 4, 20 | } 21 | ) 22 | -------------------------------------------------------------------------------- /vms/example/xsvm/execute/expects_context.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package execute 5 | 6 | import ( 7 | "github.com/Juneo-io/juneogo/vms/example/xsvm/block" 8 | "github.com/Juneo-io/juneogo/vms/example/xsvm/tx" 9 | ) 10 | 11 | var _ tx.Visitor = (*TxExpectsContext)(nil) 12 | 13 | func ExpectsContext(blk *block.Stateless) (bool, error) { 14 | t := TxExpectsContext{} 15 | for _, tx := range blk.Txs { 16 | if err := tx.Unsigned.Visit(&t); err != nil { 17 | return false, err 18 | } 19 | } 20 | return t.Result, nil 21 | } 22 | 23 | type TxExpectsContext struct { 24 | Result bool 25 | } 26 | 27 | func (*TxExpectsContext) Transfer(*tx.Transfer) error { 28 | return nil 29 | } 30 | 31 | func (*TxExpectsContext) Export(*tx.Export) error { 32 | return nil 33 | } 34 | 35 | func (t *TxExpectsContext) Import(*tx.Import) error { 36 | t.Result = true 37 | return nil 38 | } 39 | -------------------------------------------------------------------------------- /vms/example/xsvm/factory.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package xsvm 5 | 6 | import ( 7 | "github.com/Juneo-io/juneogo/utils/logging" 8 | "github.com/Juneo-io/juneogo/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/example/xsvm/genesis/codec.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package genesis 5 | 6 | import "github.com/Juneo-io/juneogo/vms/example/xsvm/block" 7 | 8 | const CodecVersion = block.CodecVersion 9 | 10 | var Codec = block.Codec 11 | -------------------------------------------------------------------------------- /vms/example/xsvm/genesis/genesis_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/ids" 12 | ) 13 | 14 | func TestGenesis(t *testing.T) { 15 | require := require.New(t) 16 | 17 | id, err := ids.ShortFromString("6Y3kysjF9jnHnYkdS9yGAuoHyae2eNmeV") 18 | require.NoError(err) 19 | id2, err := ids.ShortFromString("LeKrndtsMxcLMzHz3w4uo1XtLDpfi66c") 20 | require.NoError(err) 21 | 22 | genesis := Genesis{ 23 | Timestamp: 123, 24 | Allocations: []Allocation{ 25 | {Address: id, Balance: 1000000000}, 26 | {Address: id2, Balance: 3000000000}, 27 | }, 28 | } 29 | bytes, err := Codec.Marshal(CodecVersion, genesis) 30 | require.NoError(err) 31 | 32 | parsed, err := Parse(bytes) 33 | require.NoError(err) 34 | require.Equal(genesis, *parsed) 35 | } 36 | -------------------------------------------------------------------------------- /vms/example/xsvm/state/keys.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /vms/example/xsvm/tx/codec.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package tx 5 | 6 | import ( 7 | "math" 8 | 9 | "github.com/Juneo-io/juneogo/codec" 10 | "github.com/Juneo-io/juneogo/codec/linearcodec" 11 | "github.com/Juneo-io/juneogo/utils" 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 := utils.Err( 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 | -------------------------------------------------------------------------------- /vms/example/xsvm/tx/export.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package tx 5 | 6 | import "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /vms/example/xsvm/tx/import.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /vms/example/xsvm/tx/transfer.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package tx 5 | 6 | import "github.com/Juneo-io/juneogo/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/example/xsvm/tx/unsigned.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /vms/example/xsvm/tx/visitor.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/fx/factory.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /vms/metervm/build_block_with_context_vm.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package metervm 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/Juneo-io/juneogo/snow/consensus/snowman" 10 | "github.com/Juneo-io/juneogo/snow/engine/snowman/block" 11 | ) 12 | 13 | func (vm *blockVM) BuildBlockWithContext(ctx context.Context, blockCtx *block.Context) (snowman.Block, error) { 14 | if vm.buildBlockVM == nil { 15 | return vm.BuildBlock(ctx) 16 | } 17 | 18 | start := vm.clock.Time() 19 | blk, err := vm.buildBlockVM.BuildBlockWithContext(ctx, blockCtx) 20 | end := vm.clock.Time() 21 | duration := float64(end.Sub(start)) 22 | if err != nil { 23 | vm.blockMetrics.buildBlockWithContextErr.Observe(duration) 24 | return nil, err 25 | } 26 | vm.blockMetrics.buildBlockWithContext.Observe(duration) 27 | return &meterBlock{ 28 | Block: blk, 29 | vm: vm, 30 | }, nil 31 | } 32 | -------------------------------------------------------------------------------- /vms/metervm/metrics.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/utils/metric" 10 | "github.com/Juneo-io/juneogo/utils/wrappers" 11 | ) 12 | 13 | func newAverager(namespace, name string, reg prometheus.Registerer, errs *wrappers.Errs) metric.Averager { 14 | return metric.NewAveragerWithErrs( 15 | namespace, 16 | name, 17 | "time (in ns) of a "+name, 18 | reg, 19 | errs, 20 | ) 21 | } 22 | -------------------------------------------------------------------------------- /vms/nftfx/credential.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package nftfx 5 | 6 | import "github.com/Juneo-io/juneogo/vms/secp256k1fx" 7 | 8 | type Credential struct { 9 | secp256k1fx.Credential `serialize:"true"` 10 | } 11 | -------------------------------------------------------------------------------- /vms/nftfx/credential_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/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/factory.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package nftfx 5 | 6 | import ( 7 | "github.com/Juneo-io/juneogo/ids" 8 | "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /vms/nftfx/factory_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/nftfx/mint_output.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package nftfx 5 | 6 | import ( 7 | "encoding/json" 8 | 9 | "github.com/Juneo-io/juneogo/vms/components/verify" 10 | "github.com/Juneo-io/juneogo/vms/secp256k1fx" 11 | ) 12 | 13 | var _ verify.State = (*MintOutput)(nil) 14 | 15 | type MintOutput struct { 16 | verify.IsState `json:"-"` 17 | 18 | GroupID uint32 `serialize:"true" json:"groupID"` 19 | secp256k1fx.OutputOwners `serialize:"true"` 20 | } 21 | 22 | // MarshalJSON marshals Amt and the embedded OutputOwners struct 23 | // into a JSON readable format 24 | // If OutputOwners cannot be serialized then this will return error 25 | func (out *MintOutput) MarshalJSON() ([]byte, error) { 26 | result, err := out.OutputOwners.Fields() 27 | if err != nil { 28 | return nil, err 29 | } 30 | 31 | result["groupID"] = out.GroupID 32 | return json.Marshal(result) 33 | } 34 | -------------------------------------------------------------------------------- /vms/nftfx/mint_output_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /vms/platformvm/block/builder/main_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /vms/platformvm/block/executor/block_state.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package executor 5 | 6 | import ( 7 | "time" 8 | 9 | "github.com/Juneo-io/juneogo/chains/atomic" 10 | "github.com/Juneo-io/juneogo/ids" 11 | "github.com/Juneo-io/juneogo/utils/set" 12 | "github.com/Juneo-io/juneogo/vms/platformvm/block" 13 | "github.com/Juneo-io/juneogo/vms/platformvm/state" 14 | ) 15 | 16 | type proposalBlockState struct { 17 | onDecisionState state.Diff 18 | onCommitState state.Diff 19 | onAbortState state.Diff 20 | } 21 | 22 | // The state of a block. 23 | // Note that not all fields will be set for a given block. 24 | type blockState struct { 25 | proposalBlockState 26 | statelessBlock block.Block 27 | 28 | onAcceptState state.Diff 29 | onAcceptFunc func() 30 | 31 | inputs set.Set[ids.ID] 32 | timestamp time.Time 33 | atomicRequests map[ids.ID]*atomic.Requests 34 | } 35 | -------------------------------------------------------------------------------- /vms/platformvm/block/executor/options_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package executor 5 | 6 | import ( 7 | "fmt" 8 | "testing" 9 | 10 | "github.com/stretchr/testify/require" 11 | 12 | "github.com/Juneo-io/juneogo/snow/consensus/snowman" 13 | "github.com/Juneo-io/juneogo/vms/platformvm/block" 14 | ) 15 | 16 | func TestOptionsUnexpectedBlockType(t *testing.T) { 17 | tests := []block.Block{ 18 | &block.BanffAbortBlock{}, 19 | &block.BanffCommitBlock{}, 20 | &block.BanffStandardBlock{}, 21 | &block.ApricotAbortBlock{}, 22 | &block.ApricotCommitBlock{}, 23 | &block.ApricotStandardBlock{}, 24 | &block.ApricotAtomicBlock{}, 25 | } 26 | 27 | for _, blk := range tests { 28 | t.Run(fmt.Sprintf("%T", blk), func(t *testing.T) { 29 | err := blk.Visit(&options{}) 30 | require.ErrorIs(t, err, snowman.ErrNotOracle) 31 | }) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /vms/platformvm/block/parse.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package block 5 | 6 | import "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /vms/platformvm/block/visitor.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /vms/platformvm/factory.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package platformvm 5 | 6 | import ( 7 | "github.com/Juneo-io/juneogo/utils/logging" 8 | "github.com/Juneo-io/juneogo/vms" 9 | "github.com/Juneo-io/juneogo/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.Config 17 | } 18 | 19 | // New returns a new instance of the Platform Chain 20 | func (f *Factory) New(logging.Logger) (interface{}, error) { 21 | return &VM{Config: f.Config}, nil 22 | } 23 | -------------------------------------------------------------------------------- /vms/platformvm/genesis/codec.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package genesis 5 | 6 | import "github.com/Juneo-io/juneogo/vms/platformvm/block" 7 | 8 | const CodecVersion = block.CodecVersion 9 | 10 | var Codec = block.GenesisCodec 11 | -------------------------------------------------------------------------------- /vms/platformvm/main_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/platformvm/network/main_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/platformvm/network/tx_verifier.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package network 5 | 6 | import ( 7 | "sync" 8 | 9 | "github.com/Juneo-io/juneogo/vms/platformvm/txs" 10 | ) 11 | 12 | var _ TxVerifier = (*LockedTxVerifier)(nil) 13 | 14 | type TxVerifier interface { 15 | // VerifyTx verifies that the transaction should be issued into the mempool. 16 | VerifyTx(tx *txs.Tx) error 17 | } 18 | 19 | type LockedTxVerifier struct { 20 | lock sync.Locker 21 | txVerifier TxVerifier 22 | } 23 | 24 | func (l *LockedTxVerifier) VerifyTx(tx *txs.Tx) error { 25 | l.lock.Lock() 26 | defer l.lock.Unlock() 27 | 28 | return l.txVerifier.VerifyTx(tx) 29 | } 30 | 31 | func NewLockedTxVerifier(lock sync.Locker, txVerifier TxVerifier) *LockedTxVerifier { 32 | return &LockedTxVerifier{ 33 | lock: lock, 34 | txVerifier: txVerifier, 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /vms/platformvm/signer/empty.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package signer 5 | 6 | import "github.com/Juneo-io/juneogo/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-2024, 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 | -------------------------------------------------------------------------------- /vms/platformvm/signer/signer.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package signer 5 | 6 | import ( 7 | "github.com/Juneo-io/juneogo/utils/crypto/bls" 8 | "github.com/Juneo-io/juneogo/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/platformvm/state/empty_iterator.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package state 5 | 6 | // EmptyIterator contains no stakers. 7 | var EmptyIterator StakerIterator = emptyIterator{} 8 | 9 | type emptyIterator struct{} 10 | 11 | func (emptyIterator) Next() bool { 12 | return false 13 | } 14 | 15 | func (emptyIterator) Value() *Staker { 16 | return nil 17 | } 18 | 19 | func (emptyIterator) Release() {} 20 | -------------------------------------------------------------------------------- /vms/platformvm/state/empty_iterator_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/stretchr/testify/require" 10 | ) 11 | 12 | func TestEmptyIterator(t *testing.T) { 13 | require := require.New(t) 14 | require.False(EmptyIterator.Next()) 15 | 16 | EmptyIterator.Release() 17 | 18 | require.False(EmptyIterator.Next()) 19 | require.Nil(EmptyIterator.Value()) 20 | } 21 | -------------------------------------------------------------------------------- /vms/platformvm/state/metadata_codec.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/codec" 10 | "github.com/Juneo-io/juneogo/codec/linearcodec" 11 | "github.com/Juneo-io/juneogo/utils" 12 | ) 13 | 14 | const ( 15 | CodecVersion0Tag = "v0" 16 | CodecVersion0 uint16 = 0 17 | 18 | CodecVersion1Tag = "v1" 19 | CodecVersion1 uint16 = 1 20 | ) 21 | 22 | var MetadataCodec codec.Manager 23 | 24 | func init() { 25 | c0 := linearcodec.New([]string{CodecVersion0Tag}) 26 | c1 := linearcodec.New([]string{CodecVersion0Tag, CodecVersion1Tag}) 27 | MetadataCodec = codec.NewManager(math.MaxInt32) 28 | 29 | err := utils.Err( 30 | MetadataCodec.RegisterCodec(CodecVersion0, c0), 31 | MetadataCodec.RegisterCodec(CodecVersion1, c1), 32 | ) 33 | if err != nil { 34 | panic(err) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /vms/platformvm/state/slice_iterator_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package state 5 | 6 | var _ StakerIterator = (*sliceIterator)(nil) 7 | 8 | type sliceIterator struct { 9 | index int 10 | stakers []*Staker 11 | } 12 | 13 | // NewSliceIterator returns an iterator that contains the elements of [stakers] 14 | // in order. Doesn't sort by anything. 15 | func NewSliceIterator(stakers ...*Staker) StakerIterator { 16 | return &sliceIterator{ 17 | index: -1, 18 | stakers: stakers, 19 | } 20 | } 21 | 22 | func (i *sliceIterator) Next() bool { 23 | i.index++ 24 | return i.index < len(i.stakers) 25 | } 26 | 27 | func (i *sliceIterator) Value() *Staker { 28 | return i.stakers[i.index] 29 | } 30 | 31 | func (*sliceIterator) Release() {} 32 | -------------------------------------------------------------------------------- /vms/platformvm/state/staker_status.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /vms/platformvm/state/versions.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package state 5 | 6 | import "github.com/Juneo-io/juneogo/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/txs/executor/backend.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package executor 5 | 6 | import ( 7 | "github.com/Juneo-io/juneogo/snow" 8 | "github.com/Juneo-io/juneogo/snow/uptime" 9 | "github.com/Juneo-io/juneogo/utils" 10 | "github.com/Juneo-io/juneogo/utils/timer/mockable" 11 | "github.com/Juneo-io/juneogo/vms/platformvm/config" 12 | "github.com/Juneo-io/juneogo/vms/platformvm/fx" 13 | "github.com/Juneo-io/juneogo/vms/platformvm/reward" 14 | "github.com/Juneo-io/juneogo/vms/platformvm/utxo" 15 | ) 16 | 17 | type Backend struct { 18 | Config *config.Config 19 | Ctx *snow.Context 20 | Clk *mockable.Clock 21 | Fx fx.Fx 22 | FlowChecker utxo.Verifier 23 | Uptimes uptime.Calculator 24 | Rewards reward.Calculator 25 | Bootstrapped *utils.Atomic[bool] 26 | } 27 | -------------------------------------------------------------------------------- /vms/platformvm/txs/subnet_validator.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package txs 5 | 6 | import ( 7 | "github.com/Juneo-io/juneogo/ids" 8 | "github.com/Juneo-io/juneogo/utils/constants" 9 | ) 10 | 11 | // SupernetValidator validates a supernet on the Avalanche network. 12 | type SupernetValidator struct { 13 | Validator `serialize:"true"` 14 | 15 | // ID of the supernet this validator is validating 16 | Supernet ids.ID `serialize:"true" json:"supernetID"` 17 | } 18 | 19 | // SupernetID is the ID of the supernet this validator is validating 20 | func (v *SupernetValidator) SupernetID() ids.ID { 21 | return v.Supernet 22 | } 23 | 24 | // Verify this validator is valid 25 | func (v *SupernetValidator) Verify() error { 26 | switch v.Supernet { 27 | case constants.PrimaryNetworkID: 28 | return errBadSupernetID 29 | default: 30 | return v.Validator.Verify() 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /vms/platformvm/txs/subnet_validator_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/ids" 12 | "github.com/Juneo-io/juneogo/utils/constants" 13 | ) 14 | 15 | func TestSupernetValidatorVerifySupernetID(t *testing.T) { 16 | require := require.New(t) 17 | 18 | // Error path 19 | { 20 | vdr := &SupernetValidator{ 21 | Supernet: constants.PrimaryNetworkID, 22 | } 23 | 24 | err := vdr.Verify() 25 | require.ErrorIs(err, errBadSupernetID) 26 | } 27 | 28 | // Happy path 29 | { 30 | vdr := &SupernetValidator{ 31 | Supernet: ids.GenerateTestID(), 32 | Validator: Validator{ 33 | Wght: 1, 34 | }, 35 | } 36 | 37 | require.NoError(vdr.Verify()) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /vms/platformvm/txs/txheap/by_end_time.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package txheap 5 | 6 | import ( 7 | "time" 8 | 9 | "github.com/Juneo-io/juneogo/ids" 10 | "github.com/Juneo-io/juneogo/utils/heap" 11 | "github.com/Juneo-io/juneogo/vms/platformvm/txs" 12 | ) 13 | 14 | var _ TimedHeap = (*byEndTime)(nil) 15 | 16 | type TimedHeap interface { 17 | Heap 18 | 19 | Timestamp() time.Time 20 | } 21 | 22 | type byEndTime struct { 23 | txHeap 24 | } 25 | 26 | func NewByEndTime() TimedHeap { 27 | return &byEndTime{ 28 | txHeap: txHeap{ 29 | heap: heap.NewMap[ids.ID, heapTx](func(a, b heapTx) bool { 30 | aTime := a.tx.Unsigned.(txs.Staker).EndTime() 31 | bTime := b.tx.Unsigned.(txs.Staker).EndTime() 32 | return aTime.Before(bTime) 33 | }), 34 | }, 35 | } 36 | } 37 | 38 | func (h *byEndTime) Timestamp() time.Time { 39 | return h.Peek().Unsigned.(txs.Staker).EndTime() 40 | } 41 | -------------------------------------------------------------------------------- /vms/platformvm/validators/test_manager.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/ids" 10 | "github.com/Juneo-io/juneogo/snow/validators" 11 | ) 12 | 13 | var TestManager Manager = testManager{} 14 | 15 | type testManager struct{} 16 | 17 | func (testManager) GetMinimumHeight(context.Context) (uint64, error) { 18 | return 0, nil 19 | } 20 | 21 | func (testManager) GetCurrentHeight(context.Context) (uint64, error) { 22 | return 0, nil 23 | } 24 | 25 | func (testManager) GetSupernetID(context.Context, ids.ID) (ids.ID, error) { 26 | return ids.Empty, nil 27 | } 28 | 29 | func (testManager) GetValidatorSet(context.Context, uint64, ids.ID) (map[ids.NodeID]*validators.GetValidatorOutput, error) { 30 | return nil, nil 31 | } 32 | 33 | func (testManager) OnAcceptedBlockID(ids.ID) {} 34 | -------------------------------------------------------------------------------- /vms/platformvm/warp/codec.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package warp 5 | 6 | import ( 7 | "math" 8 | 9 | "github.com/Juneo-io/juneogo/codec" 10 | "github.com/Juneo-io/juneogo/codec/linearcodec" 11 | "github.com/Juneo-io/juneogo/utils" 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 := utils.Err( 23 | lc.RegisterType(&BitSetSignature{}), 24 | Codec.RegisterCodec(CodecVersion, lc), 25 | ) 26 | if err != nil { 27 | panic(err) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /vms/platformvm/warp/constants.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package warp 5 | 6 | import "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /vms/platformvm/warp/gwarp/client.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package gwarp 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/Juneo-io/juneogo/vms/platformvm/warp" 10 | 11 | pb "github.com/Juneo-io/juneogo/proto/pb/warp" 12 | ) 13 | 14 | var _ warp.Signer = (*Client)(nil) 15 | 16 | type Client struct { 17 | client pb.SignerClient 18 | } 19 | 20 | func NewClient(client pb.SignerClient) *Client { 21 | return &Client{client: client} 22 | } 23 | 24 | func (c *Client) Sign(unsignedMsg *warp.UnsignedMessage) ([]byte, error) { 25 | resp, err := c.client.Sign(context.Background(), &pb.SignRequest{ 26 | NetworkId: unsignedMsg.NetworkID, 27 | SourceChainId: unsignedMsg.SourceChainID[:], 28 | Payload: unsignedMsg.Payload, 29 | }) 30 | if err != nil { 31 | return nil, err 32 | } 33 | return resp.Signature, nil 34 | } 35 | -------------------------------------------------------------------------------- /vms/platformvm/warp/payload/codec.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package payload 5 | 6 | import ( 7 | "github.com/Juneo-io/juneogo/codec" 8 | "github.com/Juneo-io/juneogo/codec/linearcodec" 9 | "github.com/Juneo-io/juneogo/utils" 10 | "github.com/Juneo-io/juneogo/utils/units" 11 | ) 12 | 13 | const ( 14 | CodecVersion = 0 15 | 16 | MaxMessageSize = 24 * units.KiB 17 | ) 18 | 19 | var Codec codec.Manager 20 | 21 | func init() { 22 | Codec = codec.NewManager(MaxMessageSize) 23 | lc := linearcodec.NewDefault() 24 | 25 | err := utils.Err( 26 | lc.RegisterType(&Hash{}), 27 | lc.RegisterType(&AddressedCall{}), 28 | Codec.RegisterCodec(CodecVersion, lc), 29 | ) 30 | if err != nil { 31 | panic(err) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /vms/platformvm/warp/signer_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package warp 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/stretchr/testify/require" 10 | 11 | "github.com/Juneo-io/juneogo/ids" 12 | "github.com/Juneo-io/juneogo/utils/constants" 13 | "github.com/Juneo-io/juneogo/utils/crypto/bls" 14 | ) 15 | 16 | func TestSigner(t *testing.T) { 17 | for name, test := range SignerTests { 18 | t.Run(name, func(t *testing.T) { 19 | sk, err := bls.NewSecretKey() 20 | require.NoError(t, err) 21 | 22 | chainID := ids.GenerateTestID() 23 | s := NewSigner(sk, constants.UnitTestID, chainID) 24 | 25 | test(t, s, sk, constants.UnitTestID, chainID) 26 | }) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /vms/propertyfx/burn_operation.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package propertyfx 5 | 6 | import ( 7 | "github.com/Juneo-io/juneogo/snow" 8 | "github.com/Juneo-io/juneogo/vms/components/verify" 9 | "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /vms/propertyfx/burn_operation_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/vms/components/verify" 12 | "github.com/Juneo-io/juneogo/vms/secp256k1fx" 13 | ) 14 | 15 | func TestBurnOperationInvalid(t *testing.T) { 16 | op := BurnOperation{Input: secp256k1fx.Input{ 17 | SigIndices: []uint32{1, 0}, 18 | }} 19 | err := op.Verify() 20 | require.ErrorIs(t, err, secp256k1fx.ErrInputIndicesNotSortedUnique) 21 | } 22 | 23 | func TestBurnOperationNumberOfOutput(t *testing.T) { 24 | op := BurnOperation{} 25 | require.Empty(t, op.Outs()) 26 | } 27 | 28 | func TestBurnOperationState(t *testing.T) { 29 | intf := interface{}(&BurnOperation{}) 30 | _, ok := intf.(verify.State) 31 | require.False(t, ok) 32 | } 33 | -------------------------------------------------------------------------------- /vms/propertyfx/credential.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package propertyfx 5 | 6 | import "github.com/Juneo-io/juneogo/vms/secp256k1fx" 7 | 8 | type Credential struct { 9 | secp256k1fx.Credential `serialize:"true"` 10 | } 11 | -------------------------------------------------------------------------------- /vms/propertyfx/credential_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/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/factory.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package propertyfx 5 | 6 | import ( 7 | "github.com/Juneo-io/juneogo/ids" 8 | "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /vms/propertyfx/factory_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /vms/propertyfx/mint_output.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package propertyfx 5 | 6 | import ( 7 | "github.com/Juneo-io/juneogo/vms/components/verify" 8 | "github.com/Juneo-io/juneogo/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-2024, 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/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /vms/propertyfx/owned_output.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package propertyfx 5 | 6 | import ( 7 | "github.com/Juneo-io/juneogo/vms/components/verify" 8 | "github.com/Juneo-io/juneogo/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-2024, 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/Juneo-io/juneogo/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/proposervm/block/codec.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package block 5 | 6 | import ( 7 | "math" 8 | 9 | "github.com/Juneo-io/juneogo/codec" 10 | "github.com/Juneo-io/juneogo/codec/linearcodec" 11 | "github.com/Juneo-io/juneogo/utils" 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 := utils.Err( 25 | lc.RegisterType(&statelessBlock{}), 26 | lc.RegisterType(&option{}), 27 | Codec.RegisterCodec(CodecVersion, lc), 28 | ) 29 | if err != nil { 30 | panic(err) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /vms/proposervm/block/header.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package block 5 | 6 | import "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /vms/proposervm/block/header_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /vms/proposervm/block/option.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package block 5 | 6 | import ( 7 | "github.com/Juneo-io/juneogo/ids" 8 | "github.com/Juneo-io/juneogo/utils/hashing" 9 | ) 10 | 11 | type option struct { 12 | PrntID ids.ID `serialize:"true"` 13 | InnerBytes []byte `serialize:"true"` 14 | 15 | id ids.ID 16 | bytes []byte 17 | } 18 | 19 | func (b *option) ID() ids.ID { 20 | return b.id 21 | } 22 | 23 | func (b *option) ParentID() ids.ID { 24 | return b.PrntID 25 | } 26 | 27 | func (b *option) Block() []byte { 28 | return b.InnerBytes 29 | } 30 | 31 | func (b *option) Bytes() []byte { 32 | return b.bytes 33 | } 34 | 35 | func (b *option) initialize(bytes []byte) error { 36 | b.id = hashing.ComputeHash256Array(bytes) 37 | b.bytes = bytes 38 | return nil 39 | } 40 | -------------------------------------------------------------------------------- /vms/proposervm/block/option_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 equalOption(require *require.Assertions, want, have Block) { 9 | require.Equal(want.ID(), have.ID()) 10 | require.Equal(want.ParentID(), have.ParentID()) 11 | require.Equal(want.Block(), have.Block()) 12 | require.Equal(want.Bytes(), have.Bytes()) 13 | } 14 | -------------------------------------------------------------------------------- /vms/proposervm/block/parse.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package block 5 | 6 | import "fmt" 7 | 8 | func Parse(bytes []byte) (Block, error) { 9 | var block Block 10 | parsedVersion, err := Codec.Unmarshal(bytes, &block) 11 | if err != nil { 12 | return nil, err 13 | } 14 | if parsedVersion != CodecVersion { 15 | return nil, fmt.Errorf("expected codec version %d but got %d", CodecVersion, parsedVersion) 16 | } 17 | return block, block.initialize(bytes) 18 | } 19 | 20 | func ParseHeader(bytes []byte) (Header, error) { 21 | header := statelessHeader{} 22 | parsedVersion, err := Codec.Unmarshal(bytes, &header) 23 | if err != nil { 24 | return nil, err 25 | } 26 | if parsedVersion != CodecVersion { 27 | return nil, fmt.Errorf("expected codec version %d but got %d", CodecVersion, parsedVersion) 28 | } 29 | header.bytes = bytes 30 | return &header, nil 31 | } 32 | -------------------------------------------------------------------------------- /vms/proposervm/main_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /vms/proposervm/proposer/validators.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package proposer 5 | 6 | import ( 7 | "github.com/Juneo-io/juneogo/ids" 8 | "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /vms/proposervm/state/codec.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/codec" 10 | "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /vms/proposervm/state/state_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/database/memdb" 13 | "github.com/Juneo-io/juneogo/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/proposervm/summary/build.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/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/proposervm/summary/build_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /vms/proposervm/summary/codec.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/codec" 11 | "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /vms/proposervm/summary/parse.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /vms/rpcchainvm/ghttp/greader/reader_client.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package greader 5 | 6 | import ( 7 | "context" 8 | "errors" 9 | "io" 10 | 11 | readerpb "github.com/Juneo-io/juneogo/proto/pb/io/reader" 12 | ) 13 | 14 | var _ io.Reader = (*Client)(nil) 15 | 16 | // Client is a reader that talks over RPC. 17 | type Client struct{ client readerpb.ReaderClient } 18 | 19 | // NewClient returns a reader connected to a remote reader 20 | func NewClient(client readerpb.ReaderClient) *Client { 21 | return &Client{client: client} 22 | } 23 | 24 | func (c *Client) Read(p []byte) (int, error) { 25 | resp, err := c.client.Read(context.Background(), &readerpb.ReadRequest{ 26 | Length: int32(len(p)), 27 | }) 28 | if err != nil { 29 | return 0, err 30 | } 31 | 32 | copy(p, resp.Read) 33 | 34 | if resp.Error != nil { 35 | err = errors.New(*resp.Error) 36 | } 37 | return len(resp.Read), err 38 | } 39 | -------------------------------------------------------------------------------- /vms/rpcchainvm/ghttp/gwriter/writer_client.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package gwriter 5 | 6 | import ( 7 | "context" 8 | "errors" 9 | "io" 10 | 11 | writerpb "github.com/Juneo-io/juneogo/proto/pb/io/writer" 12 | ) 13 | 14 | var _ io.Writer = (*Client)(nil) 15 | 16 | // Client is an io.Writer that talks over RPC. 17 | type Client struct{ client writerpb.WriterClient } 18 | 19 | // NewClient returns a writer connected to a remote writer 20 | func NewClient(client writerpb.WriterClient) *Client { 21 | return &Client{client: client} 22 | } 23 | 24 | func (c *Client) Write(p []byte) (int, error) { 25 | resp, err := c.client.Write(context.Background(), &writerpb.WriteRequest{ 26 | Payload: p, 27 | }) 28 | if err != nil { 29 | return 0, err 30 | } 31 | 32 | if resp.Error != nil { 33 | err = errors.New(*resp.Error) 34 | } 35 | return int(resp.Written), err 36 | } 37 | -------------------------------------------------------------------------------- /vms/rpcchainvm/ghttp/gwriter/writer_server.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package gwriter 5 | 6 | import ( 7 | "context" 8 | "io" 9 | 10 | writerpb "github.com/Juneo-io/juneogo/proto/pb/io/writer" 11 | ) 12 | 13 | var _ writerpb.WriterServer = (*Server)(nil) 14 | 15 | // Server is an http.Handler that is managed over RPC. 16 | type Server struct { 17 | writerpb.UnsafeWriterServer 18 | writer io.Writer 19 | } 20 | 21 | // NewServer returns an http.Handler instance managed remotely 22 | func NewServer(writer io.Writer) *Server { 23 | return &Server{writer: writer} 24 | } 25 | 26 | func (s *Server) Write(_ context.Context, req *writerpb.WriteRequest) (*writerpb.WriteResponse, error) { 27 | n, err := s.writer.Write(req.Payload) 28 | resp := &writerpb.WriteResponse{ 29 | Written: int32(n), 30 | } 31 | if err != nil { 32 | errStr := err.Error() 33 | resp.Error = &errStr 34 | } 35 | return resp, nil 36 | } 37 | -------------------------------------------------------------------------------- /vms/rpcchainvm/gruntime/runtime_client.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/vms/rpcchainvm/runtime" 10 | 11 | pb "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /vms/rpcchainvm/gruntime/runtime_server.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | "google.golang.org/protobuf/types/known/emptypb" 10 | 11 | "github.com/Juneo-io/juneogo/vms/rpcchainvm/runtime" 12 | 13 | pb "github.com/Juneo-io/juneogo/proto/pb/vm/runtime" 14 | ) 15 | 16 | var _ pb.RuntimeServer = (*Server)(nil) 17 | 18 | // Server is a VM runtime initializer controlled by RPC. 19 | type Server struct { 20 | pb.UnsafeRuntimeServer 21 | runtime runtime.Initializer 22 | } 23 | 24 | func NewServer(runtime runtime.Initializer) *Server { 25 | return &Server{ 26 | runtime: runtime, 27 | } 28 | } 29 | 30 | func (s *Server) Initialize(ctx context.Context, req *pb.InitializeRequest) (*emptypb.Empty, error) { 31 | return &emptypb.Empty{}, s.runtime.Initialize(ctx, uint(req.ProtocolVersion), req.Addr) 32 | } 33 | -------------------------------------------------------------------------------- /vms/rpcchainvm/messenger/messenger_client.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package messenger 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/Juneo-io/juneogo/snow/engine/common" 10 | 11 | messengerpb "github.com/Juneo-io/juneogo/proto/pb/messenger" 12 | ) 13 | 14 | // Client is an implementation of a messenger channel that talks over RPC. 15 | type Client struct { 16 | client messengerpb.MessengerClient 17 | } 18 | 19 | // NewClient returns a client that is connected to a remote channel 20 | func NewClient(client messengerpb.MessengerClient) *Client { 21 | return &Client{client: client} 22 | } 23 | 24 | func (c *Client) Notify(msg common.Message) error { 25 | _, err := c.client.Notify(context.Background(), &messengerpb.NotifyRequest{ 26 | Message: messengerpb.Message(msg), 27 | }) 28 | return err 29 | } 30 | -------------------------------------------------------------------------------- /vms/rpcchainvm/runtime/subprocess/non_linux_stopper.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /vms/rpcchainvm/runtime/subprocess/stopper.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/utils/logging" 12 | "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /vms/secp256k1fx/factory.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package secp256k1fx 5 | 6 | import ( 7 | "github.com/Juneo-io/juneogo/ids" 8 | "github.com/Juneo-io/juneogo/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/secp256k1fx/factory_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /vms/secp256k1fx/mint_output.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package secp256k1fx 5 | 6 | import "github.com/Juneo-io/juneogo/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 | switch { 18 | case out == nil: 19 | return ErrNilOutput 20 | default: 21 | return out.OutputOwners.Verify() 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /vms/secp256k1fx/transfer_input.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /vms/secp256k1fx/tx.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | // UnsignedBytes returns Bytes 17 | func (tx *TestTx) Bytes() []byte { 18 | return tx.UnsignedBytes 19 | } 20 | -------------------------------------------------------------------------------- /vms/secp256k1fx/vm.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package secp256k1fx 5 | 6 | import ( 7 | "github.com/Juneo-io/juneogo/codec" 8 | "github.com/Juneo-io/juneogo/utils/logging" 9 | "github.com/Juneo-io/juneogo/utils/timer/mockable" 10 | ) 11 | 12 | // VM that this Fx must be run by 13 | type VM interface { 14 | CodecRegistry() codec.Registry 15 | Clock() *mockable.Clock 16 | Logger() logging.Logger 17 | } 18 | 19 | var _ VM = (*TestVM)(nil) 20 | 21 | // TestVM is a minimal implementation of a VM 22 | type TestVM struct { 23 | Clk mockable.Clock 24 | Codec codec.Registry 25 | Log logging.Logger 26 | } 27 | 28 | func (vm *TestVM) Clock() *mockable.Clock { 29 | return &vm.Clk 30 | } 31 | 32 | func (vm *TestVM) CodecRegistry() codec.Registry { 33 | return vm.Codec 34 | } 35 | 36 | func (vm *TestVM) Logger() logging.Logger { 37 | return vm.Log 38 | } 39 | -------------------------------------------------------------------------------- /vms/tracedvm/build_block_with_context_vm.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/Juneo-io/juneogo/snow/consensus/snowman" 12 | "github.com/Juneo-io/juneogo/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/types/blob_data.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package types 5 | 6 | import ( 7 | "encoding/json" 8 | 9 | "github.com/Juneo-io/juneogo/utils/formatting" 10 | ) 11 | 12 | // JSONByteSlice represents [[]byte] that is json marshalled to hex 13 | type JSONByteSlice []byte 14 | 15 | func (b JSONByteSlice) MarshalJSON() ([]byte, error) { 16 | hexData, err := formatting.Encode(formatting.HexNC, b) 17 | if err != nil { 18 | return nil, err 19 | } 20 | return json.Marshal(hexData) 21 | } 22 | -------------------------------------------------------------------------------- /wallet/chain/x/builder/constants.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package builder 5 | 6 | import ( 7 | "github.com/Juneo-io/juneogo/vms/avm/block" 8 | "github.com/Juneo-io/juneogo/vms/avm/fxs" 9 | "github.com/Juneo-io/juneogo/vms/nftfx" 10 | "github.com/Juneo-io/juneogo/vms/propertyfx" 11 | "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /wallet/supernet/primary/common/spend.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package common 5 | 6 | import ( 7 | "github.com/Juneo-io/juneogo/ids" 8 | "github.com/Juneo-io/juneogo/utils/set" 9 | "github.com/Juneo-io/juneogo/vms/secp256k1fx" 10 | ) 11 | 12 | // MatchOwners attempts to match a list of addresses up to the provided 13 | // threshold. 14 | func MatchOwners( 15 | owners *secp256k1fx.OutputOwners, 16 | addrs set.Set[ids.ShortID], 17 | minIssuanceTime uint64, 18 | ) ([]uint32, bool) { 19 | if owners.Locktime > minIssuanceTime { 20 | return nil, false 21 | } 22 | 23 | sigs := make([]uint32, 0, owners.Threshold) 24 | for i := uint32(0); i < uint32(len(owners.Addrs)) && uint32(len(sigs)) < owners.Threshold; i++ { 25 | addr := owners.Addrs[i] 26 | if addrs.Contains(addr) { 27 | sigs = append(sigs, i) 28 | } 29 | } 30 | return sigs, uint32(len(sigs)) == owners.Threshold 31 | } 32 | -------------------------------------------------------------------------------- /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. -------------------------------------------------------------------------------- /x/archivedb/value.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /x/merkledb/batch.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package merkledb 5 | 6 | import "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /x/merkledb/bytes_pool_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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_BytesPool_Acquire(b *testing.B) { 9 | s := newBytesPool(b.N) 10 | 11 | b.ResetTimer() 12 | for i := 0; i < b.N; i++ { 13 | s.Acquire() 14 | } 15 | } 16 | 17 | func Benchmark_BytesPool_Release(b *testing.B) { 18 | s := newBytesPool(b.N) 19 | for i := 0; i < b.N; i++ { 20 | s.Acquire() 21 | } 22 | 23 | b.ResetTimer() 24 | for i := 0; i < b.N; i++ { 25 | s.Release(nil) 26 | } 27 | } 28 | 29 | func Benchmark_BytesPool_TryAcquire_Success(b *testing.B) { 30 | s := newBytesPool(b.N) 31 | 32 | b.ResetTimer() 33 | for i := 0; i < b.N; i++ { 34 | s.TryAcquire() 35 | } 36 | } 37 | 38 | func Benchmark_BytesPool_TryAcquire_Failure(b *testing.B) { 39 | s := newBytesPool(1) 40 | s.Acquire() 41 | 42 | b.ResetTimer() 43 | for i := 0; i < b.N; i++ { 44 | s.TryAcquire() 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /x/merkledb/tracer.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package merkledb 5 | 6 | import "github.com/Juneo-io/juneogo/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 | -------------------------------------------------------------------------------- /x/merkledb/wait_group.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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 | -------------------------------------------------------------------------------- /x/merkledb/wait_group_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, 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/db.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 | // See the file LICENSE for licensing terms. 3 | 4 | package sync 5 | 6 | import "github.com/Juneo-io/juneogo/x/merkledb" 7 | 8 | type DB interface { 9 | merkledb.Clearer 10 | merkledb.MerkleRootGetter 11 | merkledb.ProofGetter 12 | merkledb.ChangeProofer 13 | merkledb.RangeProofer 14 | } 15 | --------------------------------------------------------------------------------