forked from aptos-labs/aptos-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[node config] allow initial set of Move modules to be chosen at genesis
The set of Move modules published at genesis is currently hardcoded. This makes it difficult to reuse the Diem software in a setting that requires a different set of initial Move modules or a different genesis state. This PR adds the bytecode for initial Move modules (represented as list of hex strings) to the `layout` part of the genesis builder, then creates the genesis transaction using this list. Closes: aptos-labs#8726
- Loading branch information
1 parent
3cd556b
commit a041020
Showing
23 changed files
with
257 additions
and
33 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (c) The Diem Core Contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use crate::builder::GenesisBuilder; | ||
use diem_management::{config::ConfigPath, error::Error, secure_backend::SharedBackend}; | ||
use diem_secure_storage::Storage; | ||
use std::{fs, path::PathBuf}; | ||
use structopt::StructOpt; | ||
|
||
#[derive(Debug, StructOpt)] | ||
pub struct SetMoveModules { | ||
#[structopt(flatten)] | ||
config: ConfigPath, | ||
// Directory containing Move bytecode (.mv) files to use in genesis | ||
#[structopt(long)] | ||
dir: PathBuf, | ||
#[structopt(flatten)] | ||
backend: SharedBackend, | ||
} | ||
|
||
impl SetMoveModules { | ||
pub fn execute(self) -> Result<Vec<Vec<u8>>, Error> { | ||
let mut move_modules = vec![]; | ||
// collect all Move bytecode files located immediately under self.dir | ||
for dir_entry in | ||
fs::read_dir(self.dir.clone()).map_err(|e| Error::UnexpectedError(e.to_string()))? | ||
{ | ||
let path = dir_entry | ||
.map_err(|e| Error::UnexpectedError(e.to_string()))? | ||
.path(); | ||
if path.is_dir() { | ||
return Err(Error::UnexpectedError(format!( | ||
"Subdirectory {:?} found under Move bytecode modules directory. All bytecode files must be located directly under the modules directory {:?}", path, self.dir))); | ||
} | ||
move_modules.push(fs::read(path).map_err(|e| Error::UnexpectedError(e.to_string()))?) | ||
} | ||
let config = self | ||
.config | ||
.load()? | ||
.override_shared_backend(&self.backend.shared_backend)?; | ||
|
||
// In order to not break cli compatibility we need to clear the namespace set via cli since | ||
// it was previously ignored. | ||
let mut shared_backend = config.shared_backend; | ||
shared_backend.clear_namespace(); | ||
|
||
let storage = Storage::from(&shared_backend); | ||
GenesisBuilder::new(storage) | ||
.set_move_modules(move_modules.clone()) | ||
.map_err(|e| Error::StorageWriteError("shared", "move_modules", e.to_string()))?; | ||
|
||
Ok(move_modules) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.