Skip to content

Commit

Permalink
Merge pull request #42 from sporeprotocol/chore/optimize-forzen-versions
Browse files Browse the repository at this point in the history
chore: optimize the loading format of frozen versions
  • Loading branch information
ashuralyk authored Jan 12, 2024
2 parents 3d84f66 + d6b56e1 commit 277fa5a
Show file tree
Hide file tree
Showing 13 changed files with 127 additions and 123 deletions.
15 changes: 1 addition & 14 deletions deployment/frozen/mainnet.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1 @@
[cluster]
code_hash_list = []

[spore]
code_hash_list = []

[cluster_proxy]
code_hash_list = []

[cluster_agent]
code_hash_list = []

[mutant]
code_hash_list = []
[[code_hash_list]]
25 changes: 5 additions & 20 deletions deployment/frozen/testnet.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
[cluster]
code_hash_list = [
# version v1 (commit: 457e32d23b5f401cad837e52a568281784943e18)
"598d793defef36e2eeba54a9b45130e4ca92822e1d193671f490950c3b856080",
]

[spore]
code_hash_list = [
# version v1 (commit: 457e32d23b5f401cad837e52a568281784943e18)
"bbad126377d45f90a8ee120da988a2d7332c78ba8fd679aab478a19d6c133494",
]

[cluster_proxy]
code_hash_list = []

[cluster_agent]
code_hash_list = []

[mutant]
code_hash_list = []
# version v1
[[code_hash_list]]
commit_hash = "457e32d23b5f401cad837e52a568281784943e18"
cluster = "598d793defef36e2eeba54a9b45130e4ca92822e1d193671f490950c3b856080"
spore = "bbad126377d45f90a8ee120da988a2d7332c78ba8fd679aab478a19d6c133494"
13 changes: 0 additions & 13 deletions deployment/migration/cluster/2024-01-05-115055.json

This file was deleted.

13 changes: 13 additions & 0 deletions deployment/migration/cluster/2024-01-11-143056.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"cell_recipes": [
{
"name": "cluster",
"tx_hash": "0x5382cd28be1da97b2e7f2824b68e3e5613441b489031eab7d1346fe4a0b9a0cf",
"index": 0,
"occupied_capacity": 3703800000000,
"data_hash": "0x3df619d2d3b80b561394c57df504f3f13e1a1e3a0ea6f3f61ad2cc1da5af9911",
"type_id": "0xd70ad85c0b3c377b3f9d73f53e110de6c853139340e12aa667bba9db749ae876"
}
],
"dep_group_recipes": []
}
13 changes: 0 additions & 13 deletions deployment/migration/cluster_agent/2024-01-05-115132.json

This file was deleted.

13 changes: 13 additions & 0 deletions deployment/migration/cluster_agent/2024-01-11-143147.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"cell_recipes": [
{
"name": "cluster_agent",
"tx_hash": "0xca7792c1b373afa1a0ff859e202a4ce4dee080c04bc896143fddae2016f69205",
"index": 0,
"occupied_capacity": 5034200000000,
"data_hash": "0x8b9c430c56be8194c4a7796ea88f54e8669f7832e5b6cd6aed5d69b91b9d0c85",
"type_id": "0xbfe31502db747a6a90e20d88c7a3819e339f78200691b11057323fbdf85754fe"
}
],
"dep_group_recipes": []
}
13 changes: 0 additions & 13 deletions deployment/migration/cluster_proxy/2024-01-05-115210.json

This file was deleted.

13 changes: 13 additions & 0 deletions deployment/migration/cluster_proxy/2024-01-11-143206.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"cell_recipes": [
{
"name": "cluster_proxy",
"tx_hash": "0x67b99c9846262cfd459cbbada20d59c16c88d12d80f3841d19e0d5d612830de8",
"index": 0,
"occupied_capacity": 3311000000000,
"data_hash": "0xe91ea54245f007c9e0a8cea49e4ae40b4ebdbfa9fa4d52bc942c6772c0094767",
"type_id": "0x969aefb1207e9694919686bbc1605c7d66322a2974bdc81b96e6b645bfc4a1d3"
}
],
"dep_group_recipes": []
}
13 changes: 0 additions & 13 deletions deployment/migration/spore/2024-01-05-115020.json

This file was deleted.

13 changes: 13 additions & 0 deletions deployment/migration/spore/2024-01-11-142958.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"cell_recipes": [
{
"name": "spore",
"tx_hash": "0x024b39f1e840548a5f4c915ced950a79dbd0c78954290e472c995eb83f72b7cf",
"index": 0,
"occupied_capacity": 7907000000000,
"data_hash": "0x86973384d661ac5aabd581de082b04726d74705fa0f97602faf10089be0a0f85",
"type_id": "0x657323d5a9672e35deb3d46500c140b511208f111fc233eeee74545634e2ebee"
}
],
"dep_group_recipes": []
}
13 changes: 0 additions & 13 deletions deployment/migration/spore_extension_lua/2024-01-05-115243.json

This file was deleted.

13 changes: 13 additions & 0 deletions deployment/migration/spore_extension_lua/2024-01-11-143252.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"cell_recipes": [
{
"name": "spore_extension_lua",
"tx_hash": "0xe6f6624bf28207aaf9c8e812723da28c27af54f6f262c8a314662dd11079e9f9",
"index": 0,
"occupied_capacity": 4181400000000,
"data_hash": "0x6e9a921ae3bfbf132b1380fd35e151806b7b0413291094bdd4bd33ca7baef415",
"type_id": "0x43befa1e7081db9b2741ce98d20707f46474d19b49b2b765f832696cacc39341"
}
],
"dep_group_recipes": []
}
80 changes: 56 additions & 24 deletions lib/build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,24 @@ use std::env;
use std::fs;

#[derive(serde::Deserialize)]
struct CodeHashList {
code_hash_list: Vec<String>,
pub struct FrozenVersions {
code_hash_list: Vec<PublishedCodeHash>,
}

#[derive(serde::Deserialize)]
pub struct PublishedCodeHash {
spore: CodeHashList,
cluster: CodeHashList,
cluster_proxy: CodeHashList,
cluster_agent: CodeHashList,
mutant: CodeHashList,
#[serde(rename(deserialize = "commit_hash"))]
_commit_hash: String,
#[serde(default)]
spore: String,
#[serde(default)]
cluster: String,
#[serde(default)]
cluster_proxy: String,
#[serde(default)]
cluster_agent: String,
#[serde(default)]
mutant: String,
}

fn hex_to_byte32(hex: &str) -> [u8; 32] {
Expand All @@ -23,49 +30,74 @@ fn hex_to_byte32(hex: &str) -> [u8; 32] {
byte32
}

impl PublishedCodeHash {
impl FrozenVersions {
pub fn spore_code_hashes(&self) -> Vec<[u8; 32]> {
self.spore
.code_hash_list
self.code_hash_list
.iter()
.map(|v| hex_to_byte32(v))
.filter_map(|v| {
if !v.spore.is_empty() {
Some(hex_to_byte32(&v.spore))
} else {
None
}
})
.collect()
}

pub fn cluster_code_hashes(&self) -> Vec<[u8; 32]> {
self.cluster
.code_hash_list
self.code_hash_list
.iter()
.map(|v| hex_to_byte32(v))
.filter_map(|v| {
if !v.cluster.is_empty() {
Some(hex_to_byte32(&v.cluster))
} else {
None
}
})
.collect()
}

pub fn cluster_proxy_code_hashes(&self) -> Vec<[u8; 32]> {
self.cluster_proxy
.code_hash_list
self.code_hash_list
.iter()
.map(|v| hex_to_byte32(v))
.filter_map(|v| {
if !v.cluster_proxy.is_empty() {
Some(hex_to_byte32(&v.cluster_proxy))
} else {
None
}
})
.collect()
}

pub fn cluster_agent_code_hashes(&self) -> Vec<[u8; 32]> {
self.cluster_agent
.code_hash_list
self.code_hash_list
.iter()
.map(|v| hex_to_byte32(v))
.filter_map(|v| {
if !v.cluster_agent.is_empty() {
Some(hex_to_byte32(&v.cluster_agent))
} else {
None
}
})
.collect()
}

pub fn mutant_code_hashes(&self) -> Vec<[u8; 32]> {
self.mutant
.code_hash_list
self.code_hash_list
.iter()
.map(|v| hex_to_byte32(v))
.filter_map(|v| {
if !v.mutant.is_empty() {
Some(hex_to_byte32(&v.mutant))
} else {
None
}
})
.collect()
}
}

pub fn load_frozen_toml() -> PublishedCodeHash {
pub fn load_frozen_toml() -> FrozenVersions {
let net_type = if env::var("CARGO_FEATURE_RELEASE_EXPORT").is_ok() {
"mainnet"
} else {
Expand Down

0 comments on commit 277fa5a

Please sign in to comment.