Skip to content

Commit c236c51

Browse files
committed
start validator fullnode
[feature] start VFN
1 parent 62b8910 commit c236c51

File tree

10 files changed

+137
-42
lines changed

10 files changed

+137
-42
lines changed

aptos-node/src/storage.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ use aptos_indexer_grpc_table_info::internal_indexer_db_service::InternalIndexerD
1111
use aptos_logger::{debug, info};
1212
use aptos_storage_interface::{DbReader, DbReaderWriter};
1313
use aptos_types::{
14-
ledger_info::LedgerInfoWithSignatures, transaction::Version, waypoint::Waypoint,
14+
ledger_info::{set_waypoint_version, LedgerInfoWithSignatures},
15+
transaction::Version,
16+
waypoint::Waypoint,
1517
};
1618
use aptos_vm::aptos_vm::AptosVMBlockExecutor;
1719
use either::Either;
@@ -195,10 +197,12 @@ pub fn initialize_database_and_checkpoints(
195197
instant.elapsed().as_millis()
196198
);
197199

200+
let waypoint = node_config.base.waypoint.waypoint();
201+
set_waypoint_version(waypoint.version());
198202
Ok((
199203
db_rw,
200204
backup_service,
201-
node_config.base.waypoint.genesis_waypoint(),
205+
waypoint,
202206
indexer_db_opt,
203207
update_receiver,
204208
))

movement-migration/validation-tool/src/checks/api.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// Copyright (c) Aptos Foundation
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use crate::checks::api::active_feature_flags::GlobalFeatureCheck;
5-
use crate::types::api::MovementAptosRestClient;
4+
use crate::{
5+
checks::api::active_feature_flags::GlobalFeatureCheck, types::api::MovementAptosRestClient,
6+
};
67
use clap::Parser;
78

89
mod active_feature_flags;

movement-migration/validation-tool/src/checks/api/active_feature_flags.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
// Copyright (c) Aptos Foundation
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use crate::checks::error::ValidationError;
5-
use crate::types::api::MovementAptosRestClient;
4+
use crate::{checks::error::ValidationError, types::api::MovementAptosRestClient};
65
use aptos_rest_client::aptos_api_types::ViewFunction;
7-
use move_core_types::identifier::Identifier;
8-
use move_core_types::language_storage::ModuleId;
6+
use move_core_types::{identifier::Identifier, language_storage::ModuleId};
97
use std::str::FromStr;
108
use tracing::debug;
119

state-sync/inter-component/event-notifications/src/lib.rs

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use aptos_storage_interface::{
1313
use aptos_types::{
1414
contract_event::ContractEvent,
1515
event::EventKey,
16+
ledger_info::get_waypoint_version,
1617
on_chain_config::{
1718
ConfigurationResource, OnChainConfig, OnChainConfigPayload, OnChainConfigProvider,
1819
},
@@ -283,41 +284,51 @@ impl EventSubscriptionService {
283284
&self,
284285
version: Version,
285286
) -> Result<OnChainConfigPayload<DbBackedOnChainConfig>, Error> {
286-
let db_state_view = &self
287-
.storage
288-
.read()
289-
.reader
290-
.state_view_at_version(Some(version))
287+
// Check if the requested version is below the minimum available version (waypoint)
288+
let reader = self.storage.read().reader.clone();
289+
let min_available_version = reader
290+
.get_first_txn_version()
291+
.map_err(|e| {
292+
Error::UnexpectedErrorEncountered(format!(
293+
"Failed to get first transaction version: {:?}",
294+
e
295+
))
296+
})?
297+
.unwrap_or(0);
298+
let effective_version = if version < min_available_version {
299+
min_available_version
300+
} else {
301+
version
302+
};
303+
304+
let db_state_view = &reader
305+
.state_view_at_version(Some(effective_version))
291306
.map_err(|error| {
292307
Error::UnexpectedErrorEncountered(format!(
293308
"Failed to create account state view {:?}",
294309
error
295310
))
296311
})?;
297312

298-
let mut epoch = ConfigurationResource::fetch_config(&db_state_view)
313+
let mut epoch = ConfigurationResource::fetch_config(db_state_view)
299314
.ok_or_else(|| {
300315
Error::UnexpectedErrorEncountered("Configuration resource does not exist!".into())
301316
})?
302317
.epoch();
303318

304-
let db_epoch_state = self
305-
.storage
306-
.read()
307-
.reader
308-
.get_latest_epoch_state()
309-
.map_err(|_e| {
310-
Error::UnexpectedErrorEncountered("Cannot read epoch state from DB".into())
311-
})?;
319+
let db_epoch_state = reader.get_latest_epoch_state().map_err(|_e| {
320+
Error::UnexpectedErrorEncountered("Cannot read epoch state from DB".into())
321+
})?;
312322
// TODO(l1-migration): update once config fixed
313323
if epoch < db_epoch_state.epoch {
314324
epoch = db_epoch_state.epoch;
315325
}
316326

317327
// Return the new on-chain config payload (containing all found configs at this version).
328+
// Use the effective version for the DbBackedOnChainConfig
318329
Ok(OnChainConfigPayload::new(
319330
epoch,
320-
DbBackedOnChainConfig::new(self.storage.read().reader.clone(), version),
331+
DbBackedOnChainConfig::new(reader, effective_version),
321332
))
322333
}
323334
}
@@ -404,7 +415,11 @@ pub struct DbBackedOnChainConfig {
404415
}
405416

406417
impl DbBackedOnChainConfig {
407-
pub fn new(reader: Arc<dyn DbReader>, version: Version) -> Self {
418+
pub fn new(reader: Arc<dyn DbReader>, mut version: Version) -> Self {
419+
let waypoint_version = get_waypoint_version().expect("Waypoint version is missing");
420+
if version < waypoint_version {
421+
version = waypoint_version as Version;
422+
}
408423
Self { reader, version }
409424
}
410425
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0:fb098815125443b6337c61b81aade770e7dcf69d93e8a636365a664939f100a3
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
base:
2+
data_dir: /Users/bowu/data/.maptos # update to your path
3+
role: full_node
4+
waypoint:
5+
from_file: /Users/bowu/data/.maptos/mainnet/waypoint.txt # update to your path
6+
7+
execution:
8+
genesis_file_location: /Users/bowu/data/.maptos/mainnet/genesis.blob # update to your path
9+
genesis_waypoint:
10+
from_file: /Users/bowu/data/.maptos/mainnet/genesis_waypoint.txt
11+
12+
storage:
13+
rocksdb_configs:
14+
enable_storage_sharding: false
15+
16+
full_node_networks:
17+
- network_id:
18+
private: "vfn"
19+
listen_address: "/ip4/0.0.0.0/tcp/6181"
20+
seeds:
21+
00000000000000000000000000000000d58bc7bb154b38039bc9096ce04e1237:
22+
addresses:
23+
- "/ip4/100.112.207.119/tcp/6181/noise-ik/f0274c2774519281a8332d0bb9d8101bd58bc7bb154b38039bc9096ce04e1237/handshake/0"
24+
role: "Validator"
25+
26+
api:
27+
enabled: true
28+
address: 0.0.0.0:8080 # Different port from validator
29+
30+
state_sync:
31+
state_sync_driver:
32+
bootstrapping_mode: DownloadLatestStates
33+
continuous_syncing_mode: ApplyTransactionOutputs

tools/l1-migration/local-node-configs/validator_node.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ validator_network:
3131
type: from_file
3232
path: /Users/bowu/data/.maptos/operator_keys/mainnet/validator-identity.yaml # update to your path
3333
listen_address: /ip4/0.0.0.0/tcp/6180
34+
full_node_networks:
35+
- network_id:
36+
private: "vfn"
37+
listen_address: "/ip4/0.0.0.0/tcp/6181"
38+
identity:
39+
type: "from_config"
40+
key: "b0f405a3e75516763c43a2ae1d70423699f34cd68fa9f8c6bb2d67aa87d0af69"
41+
peer_id: "00000000000000000000000000000000d58bc7bb154b38039bc9096ce04e1237"
3442
api:
3543
enabled: true
3644
address: 0.0.0.0:8080

tools/l1-migration/src/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use anyhow::{anyhow, Result};
2-
use aptos_crypto::x25519;
1+
use anyhow::Result;
32
use clap::Parser;
43
use l1_migration::extract_genesis_and_waypoint;
54
use std::path::PathBuf;

tools/l1-migration/src/utils.rs

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
11
use anyhow::Result;
2-
use aptos_config::config::{
3-
Peer, PeerRole, PeerSet, RocksdbConfigs, StorageDirPaths, NO_OP_STORAGE_PRUNER_CONFIG,
4-
};
5-
use aptos_crypto::{x25519, ValidCryptoMaterialStringExt};
2+
use aptos_config::config::{RocksdbConfigs, StorageDirPaths, NO_OP_STORAGE_PRUNER_CONFIG};
63
use aptos_db::AptosDB;
74
use aptos_storage_interface::DbReader;
8-
use aptos_types::{
9-
account_address::from_identity_public_key, network_address::NetworkAddress,
10-
transaction::Transaction, waypoint::Waypoint, PeerId,
11-
};
12-
use serde_yaml;
13-
use std::{
14-
collections::{HashMap, HashSet},
15-
fs,
16-
path::Path,
17-
str::FromStr,
18-
};
5+
use aptos_types::{transaction::Transaction, waypoint::Waypoint};
6+
use std::{fs, path::Path};
197

208
/// Extract genesis transaction and waypoint from an Aptos database
219
pub fn extract_genesis_and_waypoint(db_path: &str, output_dir: &str) -> Result<()> {
@@ -51,11 +39,15 @@ pub fn extract_genesis_and_waypoint(db_path: &str, output_dir: &str) -> Result<(
5139
// Extract genesis transaction
5240
extract_genesis_transaction(&db, latest_ver, output_dir)?;
5341

42+
// Extract genesis waypoint
43+
extract_genesis_waypoint(&db, latest_ver, output_dir)?;
44+
5445
// Extract waypoint
5546
extract_waypoint(&db, output_dir)?;
5647

5748
println!("✓ Genesis extraction completed successfully!");
5849
println!(" - genesis.blob: Contains the BCS-serialized genesis transaction");
50+
println!(" - genesis_waypoint.txt: Contains the genesis waypoint for bootstrapping");
5951
println!(" - waypoint.txt: Contains the initial waypoint for bootstrapping");
6052

6153
Ok(())
@@ -82,6 +74,30 @@ fn extract_genesis_transaction(db: &AptosDB, latest_ver: u64, output_dir: &str)
8274
Ok(())
8375
}
8476

77+
/// Extract the genesis waypoint from the database at version 0
78+
fn extract_genesis_waypoint(db: &AptosDB, _latest_ver: u64, output_dir: &str) -> Result<()> {
79+
println!("Extracting genesis waypoint (version 0)...");
80+
81+
// Get the epoch ending ledger info for version 0 (genesis)
82+
// This should always exist for a properly initialized database
83+
let genesis_ledger_info_with_sigs = db
84+
.get_epoch_ending_ledger_info(0)
85+
.expect("genesis waypoint should exist");
86+
87+
let genesis_ledger_info = genesis_ledger_info_with_sigs.ledger_info();
88+
89+
// Generate genesis waypoint using the genesis ledger info
90+
let genesis_waypoint = Waypoint::new_any(genesis_ledger_info);
91+
92+
// Write genesis_waypoint.txt
93+
let genesis_waypoint_path = format!("{}/genesis_waypoint.txt", output_dir);
94+
fs::write(&genesis_waypoint_path, genesis_waypoint.to_string())?;
95+
println!("Genesis waypoint written to: {}", genesis_waypoint_path);
96+
println!("Genesis waypoint: {}", genesis_waypoint);
97+
98+
Ok(())
99+
}
100+
85101
/// Extract the waypoint from the database using proper waypoint conversion
86102
fn extract_waypoint(db: &AptosDB, output_dir: &str) -> Result<()> {
87103
// Get the ledger info to extract waypoint

types/src/ledger_info.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,23 @@ use std::{
2828
ops::{Deref, DerefMut},
2929
sync::{
3030
atomic::{AtomicBool, Ordering},
31-
Arc,
31+
Arc, OnceLock,
3232
},
3333
};
3434

35+
/// Global waypoint version storage for bypassing verification of historical data
36+
static WAYPOINT_VERSION: OnceLock<Version> = OnceLock::new();
37+
38+
/// Initialize the waypoint version (should be called once during node startup)
39+
pub fn set_waypoint_version(version: Version) {
40+
let _ = WAYPOINT_VERSION.set(version);
41+
}
42+
43+
/// Get the waypoint version if it has been set
44+
pub fn get_waypoint_version() -> Option<Version> {
45+
WAYPOINT_VERSION.get().copied()
46+
}
47+
3548
/// This structure serves a dual purpose.
3649
///
3750
/// First, if this structure is signed by 2f+1 validators it signifies the state of the ledger at
@@ -305,6 +318,13 @@ impl LedgerInfoWithV0 {
305318
&self,
306319
validator: &ValidatorVerifier,
307320
) -> ::std::result::Result<(), VerifyError> {
321+
// Check if this LedgerInfo is before the waypoint version
322+
if let Some(waypoint_version) = get_waypoint_version() {
323+
if self.ledger_info().version() <= waypoint_version {
324+
return Ok(());
325+
}
326+
}
327+
308328
validator.verify_multi_signatures(self.ledger_info(), &self.signatures)
309329
}
310330

0 commit comments

Comments
 (0)