Skip to content

Commit 67a06c5

Browse files
Seulgi Kimsgkim126
authored andcommitted
Add worlds to the Shard spec
1 parent 6724405 commit 67a06c5

File tree

9 files changed

+96
-13
lines changed

9 files changed

+96
-13
lines changed

core/res/blake_pow.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@
4040
"9cce34f7ab185c7aba1b7c8140d620b4bda941d6": { "balance": "1606938044258990275541962092341162602522202993782792835301376", "nonce": "0" }
4141
},
4242
"shards": {
43-
"0": { "nonce": 0, "owner": "0x9cce34f7ab185c7aba1b7c8140d620b4bda941d6" }
43+
"0": {
44+
"nonce": 0,
45+
"owner": "0x9cce34f7ab185c7aba1b7c8140d620b4bda941d6",
46+
"worlds": [{
47+
"nonce": 0,
48+
"owners": [
49+
"0x9cce34f7ab185c7aba1b7c8140d620b4bda941d6",
50+
"0xa6594b7196808d161b6fb137e781abbc251385d9"
51+
]
52+
}]
53+
}
4454
}
4555
}

core/res/cuckoo.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@
4343
"9cce34f7ab185c7aba1b7c8140d620b4bda941d6": { "balance": "1606938044258990275541962092341162602522202993782792835301376", "nonce": "0" }
4444
},
4545
"shards": {
46-
"0": { "nonce": 0, "owner": "0x9cce34f7ab185c7aba1b7c8140d620b4bda941d6" }
46+
"0": {
47+
"nonce": 0,
48+
"owner": "0x9cce34f7ab185c7aba1b7c8140d620b4bda941d6",
49+
"worlds": [{
50+
"nonce": 0,
51+
"owners": [
52+
"0x9cce34f7ab185c7aba1b7c8140d620b4bda941d6",
53+
"0xa6594b7196808d161b6fb137e781abbc251385d9"
54+
]
55+
}]
56+
}
4757
}
4858
}

core/res/null.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@
3737
"9cce34f7ab185c7aba1b7c8140d620b4bda941d6": { "balance": "1606938044258990275541962092341162602522202993782792835301376", "nonce": "0" }
3838
},
3939
"shards": {
40-
"0": { "nonce": 0, "owner": "0x9cce34f7ab185c7aba1b7c8140d620b4bda941d6" }
40+
"0": {
41+
"nonce": 0,
42+
"owner": "0x9cce34f7ab185c7aba1b7c8140d620b4bda941d6",
43+
"worlds": [{
44+
"nonce": 0,
45+
"owners": [
46+
"0x9cce34f7ab185c7aba1b7c8140d620b4bda941d6",
47+
"0xa6594b7196808d161b6fb137e781abbc251385d9"
48+
]
49+
}]
50+
}
4151
}
4252
}

core/res/solo.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@
3838
"9cce34f7ab185c7aba1b7c8140d620b4bda941d6": { "balance": "1606938044258990275541962092341162602522202993782792835301376", "nonce": "0" }
3939
},
4040
"shards": {
41-
"0": { "nonce": 0, "owner": "0x9cce34f7ab185c7aba1b7c8140d620b4bda941d6" }
41+
"0": {
42+
"nonce": 0,
43+
"owner": "0x9cce34f7ab185c7aba1b7c8140d620b4bda941d6",
44+
"worlds": [{
45+
"nonce": 0,
46+
"owners": [
47+
"0x9cce34f7ab185c7aba1b7c8140d620b4bda941d6",
48+
"0xa6594b7196808d161b6fb137e781abbc251385d9"
49+
]
50+
}]
51+
}
4252
}
4353
}

core/res/solo_authority.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@
4242
"9cce34f7ab185c7aba1b7c8140d620b4bda941d6": { "balance": "1606938044258990275541962092341162602522202993782792835301376", "nonce": "0" }
4343
},
4444
"shards": {
45-
"0": { "nonce": 0, "owner": "0x9cce34f7ab185c7aba1b7c8140d620b4bda941d6" }
45+
"0": {
46+
"nonce": 0,
47+
"owner": "0x9cce34f7ab185c7aba1b7c8140d620b4bda941d6",
48+
"worlds": [{
49+
"nonce": 0,
50+
"owners": [
51+
"0x9cce34f7ab185c7aba1b7c8140d620b4bda941d6",
52+
"0xa6594b7196808d161b6fb137e781abbc251385d9"
53+
]
54+
}]
55+
}
4656
}
4757
}

core/res/tendermint.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@
5454
"9cce34f7ab185c7aba1b7c8140d620b4bda941d6": { "balance": "1606938044258990275541962092341162602522202993782792835301376", "nonce": "0" }
5555
},
5656
"shards": {
57-
"0": { "nonce": 0, "owner": "0x9cce34f7ab185c7aba1b7c8140d620b4bda941d6" }
57+
"0": {
58+
"nonce": 0,
59+
"owner": "0x9cce34f7ab185c7aba1b7c8140d620b4bda941d6",
60+
"worlds": [{
61+
"nonce": 0,
62+
"owners": [
63+
"0x9cce34f7ab185c7aba1b7c8140d620b4bda941d6",
64+
"0xa6594b7196808d161b6fb137e781abbc251385d9"
65+
]
66+
}]
67+
}
5868
}
5969
}

core/src/spec/pod_shard_metadata.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,21 @@ use std::fmt;
1919
use cjson;
2020
use ckey::Address;
2121
use cstate::ShardMetadata;
22-
use ctypes::ShardId;
2322
use rlp::{Encodable, RlpStream};
2423

24+
use super::pod_world::PodWorld;
25+
2526
#[derive(Clone, Debug, Eq, PartialEq)]
2627
pub struct PodShardMetadata {
2728
pub owner: Address,
28-
pub number_of_worlds: ShardId,
2929
pub nonce: u64,
30+
pub worlds: Vec<PodWorld>,
3031
}
3132

3233
impl<'a> Into<ShardMetadata> for &'a PodShardMetadata {
3334
fn into(self) -> ShardMetadata {
34-
ShardMetadata::new_with_nonce(self.number_of_worlds, self.nonce)
35+
assert!(self.worlds.len() <= ::std::u16::MAX as usize);
36+
ShardMetadata::new_with_nonce(self.worlds.len() as u16, self.nonce)
3537
}
3638
}
3739

@@ -45,15 +47,15 @@ impl Encodable for PodShardMetadata {
4547
impl From<cjson::spec::Shard> for PodShardMetadata {
4648
fn from(s: cjson::spec::Shard) -> Self {
4749
Self {
48-
number_of_worlds: 0,
4950
nonce: s.nonce.map(Into::into).unwrap_or(0),
5051
owner: s.owner,
52+
worlds: s.worlds.unwrap_or_else(Vec::new).into_iter().map(Into::into).collect(),
5153
}
5254
}
5355
}
5456

5557
impl fmt::Display for PodShardMetadata {
5658
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
57-
write!(f, "(#wordls={}; nonce={}; owner={})", self.number_of_worlds, self.nonce, self.owner)
59+
write!(f, "(#nonce={}; owner={}; worlds={:#?})", self.nonce, self.owner, self.worlds)
5860
}
5961
}

core/src/spec/spec.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use ckey::Address;
2323
use cmerkle::TrieFactory;
2424
use cstate::{
2525
ActionHandler, Backend, Metadata, MetadataAddress, Shard, ShardAddress, ShardMetadataAddress, StateDB, StateResult,
26+
WorldAddress,
2627
};
2728
use ctypes::ShardId;
2829
use hashdb::HashDB;
@@ -199,6 +200,15 @@ impl Spec {
199200
let r = t.insert(&*address, &shard.rlp_bytes());
200201
debug_assert_eq!(Ok(None), r);
201202
r?;
203+
204+
assert!(shard.worlds.len() <= ::std::u16::MAX as usize);
205+
for (world_id, world) in shard.worlds.iter().enumerate() {
206+
let address = WorldAddress::new(*shard_id, world_id as u16);
207+
208+
let r = t.insert(&*address, &world.rlp_bytes());
209+
debug_assert_eq!(Ok(None), r);
210+
r?;
211+
}
202212
}
203213
let owner = shard.owner;
204214
shard_roots.push((*shard_id, shard_root, owner));

json/src/spec/shard.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
use primitives::H160;
1818

1919
use super::super::uint::Uint;
20+
use super::World;
2021

2122
#[derive(Debug, PartialEq, Deserialize)]
2223
pub struct Shard {
2324
pub nonce: Option<Uint>,
2425
pub owner: H160,
25-
// FIXME: Add worlds
26+
pub worlds: Option<Vec<World>>,
2627
}
2728

2829
#[cfg(test)]
@@ -36,13 +37,21 @@ mod tests {
3637
fn shard_deserialization() {
3738
let s = r#"{
3839
"nonce": 0,
39-
"owner": "0x01234567890abcdef0123456789abcdef0123456"
40+
"owner": "0x01234567890abcdef0123456789abcdef0123456",
41+
"worlds": [{
42+
"nonce": 3,
43+
"owners": ["0x01234567890abcdef0123456789abcdef0123457"]
44+
}]
4045
}"#;
4146
let shard: Shard = serde_json::from_str(s).unwrap();
4247
assert_eq!(
4348
Shard {
4449
nonce: Some(Uint(U256::from(0))),
4550
owner: H160::from("01234567890abcdef0123456789abcdef0123456"),
51+
worlds: Some(vec![World {
52+
nonce: Some(Uint(U256::from(3))),
53+
owners: Some(vec![H160::from("01234567890abcdef0123456789abcdef0123457")]),
54+
}]),
4655
},
4756
shard
4857
);
@@ -59,6 +68,7 @@ mod tests {
5968
Shard {
6069
nonce: Some(Uint(U256::from(100))),
6170
owner: H160::from("01234567890abcdef0123456789abcdef0123456"),
71+
worlds: None,
6272
},
6373
shard
6474
);
@@ -83,6 +93,7 @@ mod tests {
8393
Shard {
8494
nonce: None,
8595
owner: H160::from("01234567890abcdef0123456789abcdef0123456"),
96+
worlds: None,
8697
},
8798
shard
8899
);

0 commit comments

Comments
 (0)