Skip to content

Commit

Permalink
[framework] Fix session key active bug (#1691)
Browse files Browse the repository at this point in the history
* [framework] Fix session key active bug

* fix genesis check

* fixup
  • Loading branch information
jolestar authored May 16, 2024
1 parent 885b2b7 commit ea447ce
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 34 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions crates/rooch-genesis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ move-prover = { workspace = true }
moveos-types = { workspace = true }
moveos-verifier = { workspace = true }
moveos-stdlib = { workspace = true }
framework-builder = { workspace = true }
moveos = { workspace = true }
moveos-store = { workspace = true }

rooch-framework = { workspace = true }
rooch-types = { workspace = true }
bitcoin-move = { workspace = true }
bitcoin-move = { workspace = true }

framework-builder = { workspace = true }
framework-release = { workspace = true }
2 changes: 1 addition & 1 deletion crates/rooch-genesis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ impl RoochGenesis {
}

pub fn load_stdlib(stdlib_version: StdlibVersion) -> Result<Stdlib> {
stdlib_version.load()
framework_release::load_stdlib(stdlib_version)
}

pub fn load_from<P: AsRef<Path>>(genesis_file: P) -> Result<Self> {
Expand Down
9 changes: 5 additions & 4 deletions crates/rooch-rpc-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ pub async fn run_start_server(opt: &RoochOpt, server_opt: ServerOpt) -> Result<S

let data_import_flag = opt.data_import_flag;

let genesis_file = arc_base_config.base_data_dir().path().join("genesis");
if root.is_genesis() {
let mut network: RoochNetwork = match chain_id {
RoochChainID::Builtin(chain_id) => chain_id.into(),
Expand All @@ -216,9 +215,11 @@ pub async fn run_start_server(opt: &RoochOpt, server_opt: ServerOpt) -> Result<S
network.set_sequencer_account(sequencer_account.into());
let genesis: RoochGenesis = RoochGenesis::build(network)?;
root = genesis.init_genesis(&mut moveos_store)?;
genesis.save_to(genesis_file)?;
} else {
let genesis: RoochGenesis = RoochGenesis::load_from(genesis_file)?;
} else if let RoochChainID::Builtin(chain_id) = chain_id {
let mut network: RoochNetwork = chain_id.into();
//TODO only set sequencer account if the network is local/dev
network.set_sequencer_account(sequencer_account.into());
let genesis = RoochGenesis::build(network)?;
genesis.check_genesis(moveos_store.get_config_store())?;
};

Expand Down
1 change: 0 additions & 1 deletion frameworks/framework-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ codespan-reporting = { workspace = true }
pathdiff = { workspace = true }
itertools = { workspace = true }
tracing = { workspace = true }
include_dir = { workspace = true }

move-binary-format = { workspace = true }
move-bytecode-utils = { workspace = true }
Expand Down
3 changes: 0 additions & 3 deletions frameworks/framework-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

use anyhow::{ensure, Result};
use codespan_reporting::term::termcolor::{ColorChoice, StandardStream};
use include_dir::{include_dir, Dir};
use move_binary_format::{errors::Location, CompiledModule};
use move_cli::base::reroot_path;
use move_core_types::account_address::AccountAddress;
Expand Down Expand Up @@ -329,8 +328,6 @@ where

pub(crate) const RELEASE_DIR: &str = "../framework-release/released/";

pub(crate) const STATIC_FRAMEWORK_DIR: Dir = include_dir!("../framework-release/released/");

pub(crate) fn release_dir() -> PathBuf {
path_in_crate(RELEASE_DIR)
}
20 changes: 2 additions & 18 deletions frameworks/framework-builder/src/stdlib_version.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

use crate::{release_dir, Stdlib, STATIC_FRAMEWORK_DIR};
use crate::{release_dir, Stdlib};
use anyhow::{anyhow, Result};
use serde::{Deserialize, Serialize};
use std::cmp::Ordering;
Expand Down Expand Up @@ -51,7 +51,7 @@ impl StdlibVersion {
true
}

fn dir_with_file(&self) -> PathBuf {
pub fn dir_with_file(&self) -> PathBuf {
PathBuf::from(self.to_string()).join("stdlib")
}

Expand All @@ -64,22 +64,6 @@ impl StdlibVersion {
Stdlib::load_from_file(file)
}

/// Load stdlib from static include file
pub fn load(&self) -> Result<Stdlib> {
STATIC_FRAMEWORK_DIR
.get_file(self.dir_with_file())
.ok_or_else(|| anyhow!("stdlib not found"))
.and_then(|f| {
Stdlib::decode(f.contents()).map_err(|e| {
anyhow!(
"Load stdlib from static include file {:?} failed: {:?}",
f.path(),
e
)
})
})
}

pub fn save(&self, stdlib: &Stdlib) -> Result<()> {
let file = self.output_file();
let parent = file
Expand Down
1 change: 1 addition & 0 deletions frameworks/framework-release/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ once_cell = { workspace = true }
serde = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
include_dir = { workspace = true }

move-core-types = { workspace = true }
move-binary-format = { workspace = true }
Expand Down
Binary file modified frameworks/framework-release/released/1/stdlib
Binary file not shown.
23 changes: 23 additions & 0 deletions frameworks/framework-release/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

use anyhow::{anyhow, Result};
use framework_builder::{stdlib_version::StdlibVersion, Stdlib};
use include_dir::{include_dir, Dir};

pub(crate) const STATIC_FRAMEWORK_DIR: Dir = include_dir!("released");

pub fn load_stdlib(version: StdlibVersion) -> Result<Stdlib> {
STATIC_FRAMEWORK_DIR
.get_file(version.dir_with_file())
.ok_or_else(|| anyhow!("stdlib not found"))
.and_then(|f| {
Stdlib::decode(f.contents()).map_err(|e| {
anyhow!(
"Load stdlib from static include file {:?} failed: {:?}",
f.path(),
e
)
})
})
}
3 changes: 1 addition & 2 deletions frameworks/rooch-framework/doc/transfer.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
- [Function `transfer_object`](#0x3_transfer_transfer_object)


<pre><code><b>use</b> <a href="">0x1::debug</a>;
<b>use</b> <a href="">0x1::option</a>;
<pre><code><b>use</b> <a href="">0x1::option</a>;
<b>use</b> <a href="">0x2::account</a>;
<b>use</b> <a href="">0x2::object</a>;
<b>use</b> <a href="account.md#0x3_account">0x3::account</a>;
Expand Down
10 changes: 8 additions & 2 deletions frameworks/rooch-framework/sources/session_key.move
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,15 @@ module rooch_framework::session_key {
public(friend) fun active_session_key(authentication_key: vector<u8>) {
let sender_addr = tx_context::sender();
let now_seconds = timestamp::now_seconds();
assert!(account::exists_resource<SessionKeys>(sender_addr), ErrorSessionKeyIsInvalid);
// If the session key is not exists, do nothing
// Because the user may remove the session key in the same transaction
if(!account::exists_resource<SessionKeys>(sender_addr)){
return
};
let session_keys = account::borrow_mut_resource<SessionKeys>(sender_addr);
assert!(table::contains(&session_keys.keys, authentication_key), ErrorSessionKeyIsInvalid);
if(!table::contains(&session_keys.keys, authentication_key)){
return
};
let session_key = table::borrow_mut(&mut session_keys.keys, authentication_key);
session_key.last_active_time = now_seconds;
}
Expand Down

0 comments on commit ea447ce

Please sign in to comment.