-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merk hash scheme migration #338
base: main
Are you sure you want to change the base?
Changes from all commits
9c39f12
6569168
7534813
015478f
9fc967a
186091b
df8814b
7091a87
cd7c4b7
f18d6dd
b074ef0
1332d87
de63140
18f16ea
b9f0110
c5a75b8
9cc2dcb
cac41ce
2a3767b
d33d246
71adc6b
9cb3ebe
907d5d7
e2bb5e6
050e039
0478be6
46b9aac
7e6c718
1b4b088
ca5814b
8a22532
da1bf32
dffa8b4
d3ca797
81a556c
42e5bc6
252fef6
6997d20
58ce7b0
014067d
17a4709
2554e03
5fbcb2d
3bed6b3
e745b8f
912620d
0a18e90
eb17ffd
da72e3f
c02b7fc
d0f0510
dae0b50
bcbc627
ff4fbed
b7a4c0c
90eebbc
fc8b0e9
da64fba
f575b00
2c0c000
cea55b6
a5572bf
1033b96
b01dd7c
d6291a5
86712ac
b1f5f84
a1de093
1acb6ae
30346d2
042e192
162676e
6183734
78cf28c
28f30c9
03dd4d1
def4139
6500bf4
174c927
60385a4
bd74390
6eefbd1
e2c4f17
bc7493b
63b2ce4
cf3d3c2
490f6f7
183715b
caca26c
5632885
76ff5af
702cf18
f513be6
74fb305
baa1f16
bc17301
eba86ea
0b58318
894bee5
ce75813
c24902a
a0eb7ba
35aec13
3da8121
2639e9f
3fc1954
d66869b
b70771e
95bce1e
cfdb514
f4fa962
986290c
24f91db
a83ff7d
0ca8182
e9d67c7
e62de6c
b3c8986
fa7ad3a
db0f739
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,37 @@ | ||
use clap::Parser; | ||
use many_types::ledger::TokenAmount; | ||
use merk::rocksdb::{IteratorMode, ReadOptions}; | ||
use merk::tree::Tree; | ||
use std::path::PathBuf; | ||
use { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, I'd like to keep it to one |
||
clap::Parser, | ||
derive_more::{From, TryInto}, | ||
many_types::ledger::TokenAmount, | ||
merk_v1::rocksdb::{IteratorMode, ReadOptions}, | ||
merk_v1::tree::Tree, | ||
std::path::PathBuf, | ||
}; | ||
|
||
#[derive(Parser)] | ||
struct Opts { | ||
/// The RocksDB store to load. | ||
store: PathBuf, | ||
} | ||
|
||
fn main() { | ||
type InnerStorage = merk_v2::Merk; | ||
|
||
#[derive(Debug, From, TryInto)] | ||
enum Error { | ||
Decode(minicbor::decode::Error), | ||
EndOfIterator, | ||
Merk(merk_v2::Error), | ||
Rocks(merk_v2::rocksdb::Error), | ||
} | ||
|
||
fn main() -> Result<(), Error> { | ||
let Opts { store } = Opts::parse(); | ||
|
||
let merk = merk::Merk::open(store).expect("Could not open the store."); | ||
let merk = InnerStorage::open(store)?; | ||
|
||
let it = merk.iter_opt(IteratorMode::Start, ReadOptions::default()); | ||
|
||
for kv_result in it { | ||
let (k, v) = kv_result.unwrap(); | ||
let (k, v) = kv_result?; | ||
let new_v = Tree::decode(k.to_vec(), v.as_ref()); | ||
|
||
let k: Vec<u8> = k.into(); | ||
|
@@ -27,14 +40,17 @@ fn main() { | |
// Try to "smartly" decode the key. | ||
if k.starts_with(b"/events/") { | ||
let k = hex::encode(&k[8..]); | ||
let log = minicbor::decode::<many_modules::events::EventLog>(v).unwrap(); | ||
let log = minicbor::decode::<many_modules::events::EventLog>(v)?; | ||
println!("event {k} => {log:?}",) | ||
} else if k.starts_with(b"/balances/") { | ||
let k = &k[10..]; | ||
// This should be utf8. | ||
let k = String::from_utf8_lossy(k); | ||
let mut it = k.split('/'); | ||
let (id, symbol) = (it.next().unwrap(), it.next().unwrap()); | ||
let (id, symbol) = it | ||
.next() | ||
.and_then(|id| it.next().map(|symbol| (id, symbol))) | ||
.ok_or(Error::EndOfIterator)?; | ||
let t = TokenAmount::from(v.to_vec()); | ||
println!("balance {id} => {t} {symbol}"); | ||
} else if k.starts_with(b"/multisig/") { | ||
|
@@ -47,4 +63,5 @@ fn main() { | |
println!("unknown 0x {} => {}", hex::encode(k), hex::encode(v)); | ||
} | ||
} | ||
Ok(()) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
use crate::migration::error_code::LEGACY_ERROR_CODE_TRIGGER; | ||
use crate::migration::{AbciAppMigrations, MIGRATIONS}; | ||
use coset::{CborSerializable, CoseSign1}; | ||
use many_client::client::blocking::{block_on, ManyClient}; | ||
use many_error::{ManyError, ManyErrorCode}; | ||
use many_identity::{Address, AnonymousIdentity}; | ||
use many_migration::MigrationConfig; | ||
use many_modules::abci_backend::{AbciBlock, AbciCommitInfo, AbciInfo}; | ||
use many_protocol::ResponseMessage; | ||
use reqwest::{IntoUrl, Url}; | ||
use std::sync::{Arc, RwLock}; | ||
use tendermint_abci::Application; | ||
use tendermint_proto::abci::*; | ||
use tracing::{debug, error}; | ||
use { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same. |
||
crate::migration::{error_code::LEGACY_ERROR_CODE_TRIGGER, AbciAppMigrations, MIGRATIONS}, | ||
coset::{CborSerializable, CoseSign1}, | ||
many_client::client::blocking::{block_on, ManyClient}, | ||
many_error::{ManyError, ManyErrorCode}, | ||
many_identity::{Address, AnonymousIdentity}, | ||
many_migration::MigrationConfig, | ||
many_modules::abci_backend::{AbciBlock, AbciCommitInfo, AbciInfo}, | ||
many_protocol::ResponseMessage, | ||
reqwest::{IntoUrl, Url}, | ||
std::{ | ||
path::PathBuf, | ||
sync::{Arc, RwLock}, | ||
}, | ||
tendermint_abci::Application, | ||
tendermint_proto::abci::*, | ||
tracing::{debug, error}, | ||
}; | ||
|
||
lazy_static::lazy_static!( | ||
static ref EPOCH: many_types::Timestamp = many_types::Timestamp::new(0).unwrap(); | ||
|
@@ -161,7 +165,7 @@ impl Application for AbciApp { | |
if let Ok(mut m) = self.migrations.write() { | ||
// Since it's impossible to truly handle error here, and | ||
// we don't actually want to panic, just ignore any errors. | ||
let _ = m.update_at_height(&mut (), height); | ||
let _ = m.update_at_height(&mut (), height, [""].iter().collect::<PathBuf>()); | ||
} else { | ||
error!("Migration: Could not acquire migration lock..."); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
use linkme::distributed_slice; | ||
use many_error::ManyError; | ||
use many_migration::{InnerMigration, MigrationSet}; | ||
use { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here too. |
||
linkme::distributed_slice, | ||
many_error::ManyError, | ||
many_migration::{InnerMigration, MigrationSet}, | ||
std::path::PathBuf, | ||
}; | ||
|
||
pub mod error_code; | ||
|
||
pub type AbciAppMigrations = MigrationSet<'static, ()>; | ||
pub type AbciAppMigrations = MigrationSet<'static, (), PathBuf>; | ||
|
||
// This is the global migration registry | ||
// Doesn't contain any metadata | ||
#[distributed_slice] | ||
pub static MIGRATIONS: [InnerMigration<(), ManyError>] = [..]; | ||
pub static MIGRATIONS: [InnerMigration<(), ManyError, PathBuf>] = [..]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
use crate::migration::MIGRATIONS; | ||
use linkme::distributed_slice; | ||
use many_error::ManyError; | ||
use many_migration::InnerMigration; | ||
use { | ||
crate::migration::MIGRATIONS, linkme::distributed_slice, many_error::ManyError, | ||
many_migration::InnerMigration, std::path::PathBuf, | ||
}; | ||
|
||
#[distributed_slice(MIGRATIONS)] | ||
pub static LEGACY_ERROR_CODE_TRIGGER: InnerMigration<(), ManyError> = InnerMigration::new_trigger( | ||
true, | ||
"LegacyErrorCode", | ||
"Trigger a legacy bug in attribute-specific error codes decoding in ABCI.", | ||
); | ||
pub static LEGACY_ERROR_CODE_TRIGGER: InnerMigration<(), ManyError, PathBuf> = | ||
InnerMigration::new_trigger( | ||
true, | ||
"LegacyErrorCode", | ||
"Trigger a legacy bug in attribute-specific error codes decoding in ABCI.", | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how you got this refactor... We don't use a
use { /* all imports */ }
pattern anywhere else, so if you could revert this that would be great.