Skip to content

Commit f5a3616

Browse files
committed
maybe save the powertable
1 parent e739433 commit f5a3616

File tree

6 files changed

+67
-17
lines changed

6 files changed

+67
-17
lines changed

fendermint/actors/blobs/shared/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub enum Method {
3636
GetPendingBlobs = frc42_dispatch::method_hash!("GetPendingBlobs"),
3737
FinalizeBlob = frc42_dispatch::method_hash!("FinalizeBlob"),
3838
DeleteBlob = frc42_dispatch::method_hash!("DeleteBlob"),
39+
UpdatePowerTable = frc42_dispatch::method_hash!("UpdatePowerTable"),
3940
}
4041

4142
pub fn buy_credit(rt: &impl Runtime, recipient: Address) -> Result<Account, ActorError> {

fendermint/actors/blobs/shared/src/params.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@ use fvm_shared::clock::ChainEpoch;
99
use fvm_shared::econ::TokenAmount;
1010
use serde::{Deserialize, Serialize};
1111

12-
use crate::state::{BlobStatus, Hash, PublicKey};
12+
use crate::state::{BlobStatus, Hash, PowerTable, PublicKey};
1313

1414
/// Params for buying credits.
1515
#[derive(Clone, Debug, Serialize, Deserialize)]
1616
#[serde(transparent)]
1717
pub struct BuyCreditParams(pub Address);
1818

19+
/// Push the power table to the actor.
20+
#[derive(Clone, Debug, Serialize, Deserialize)]
21+
#[serde(transparent)]
22+
pub struct UpdatePowerTableParams(pub PowerTable);
23+
1924
/// Params for approving credit.
2025
#[derive(Clone, Debug, Serialize_tuple, Deserialize_tuple)]
2126
pub struct ApproveCreditParams {

fendermint/actors/blobs/shared/src/state.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,10 @@ pub struct Subscription {
140140
pub struct Power(pub u64);
141141

142142
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
143-
pub struct PowerTable(pub Vec<Validator<Power>>);
143+
pub struct PowerTable(pub Vec<Validator>);
144144

145145
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
146-
pub struct ValidatorKey(pub PublicKey);
147-
148-
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
149-
pub struct Validator<P> {
150-
pub public_key: ValidatorKey,
151-
pub power: P,
146+
pub struct Validator {
147+
pub address: Address,
148+
pub power: Power,
152149
}

fendermint/actors/blobs/src/actor.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44

55
use std::collections::HashSet;
66

7-
use fendermint_actor_blobs_shared::params::{
8-
AddBlobParams, ApproveCreditParams, BuyCreditParams, DeleteBlobParams, FinalizeBlobParams,
9-
GetAccountParams, GetBlobParams, GetBlobStatusParams, GetPendingBlobsParams, GetStatsReturn,
10-
RevokeCreditParams,
11-
};
7+
use fendermint_actor_blobs_shared::params::{AddBlobParams, ApproveCreditParams, BuyCreditParams, DeleteBlobParams, FinalizeBlobParams, GetAccountParams, GetBlobParams, GetBlobStatusParams, GetPendingBlobsParams, GetStatsReturn, RevokeCreditParams, UpdatePowerTableParams};
128
use fendermint_actor_blobs_shared::state::{
139
Account, Blob, BlobStatus, CreditApproval, Hash, PublicKey, Subscription,
1410
};
@@ -116,6 +112,13 @@ impl BlobsActor {
116112
})
117113
}
118114

115+
fn update_power_table(rt: &impl Runtime, params: UpdatePowerTableParams) -> Result<(), ActorError> {
116+
rt.validate_immediate_caller_is(std::iter::once(&SYSTEM_ACTOR_ADDR))?;
117+
rt.transaction(|st: &mut State, _rt| {
118+
st.update_power_table(params.0)
119+
})
120+
}
121+
119122
fn revoke_credit(rt: &impl Runtime, params: RevokeCreditParams) -> Result<(), ActorError> {
120123
rt.validate_immediate_caller_accept_any()?;
121124
let (from, actor_type) = resolve_external(rt, params.from)?;
@@ -327,6 +330,7 @@ impl ActorCode for BlobsActor {
327330
GetPendingBlobs => get_pending_blobs,
328331
FinalizeBlob => finalize_blob,
329332
DeleteBlob => delete_blob,
333+
UpdatePowerTable => update_power_table,
330334
_ => fallback,
331335
}
332336
}

fendermint/actors/blobs/src/state.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ impl State {
167167
Ok(approval.clone())
168168
}
169169

170+
pub fn update_power_table(&mut self, power_table: PowerTable) -> anyhow::Result<(), ActorError> {
171+
self.power_table = power_table;
172+
Ok(())
173+
}
174+
170175
pub fn revoke_credit(
171176
&mut self,
172177
from: Address,

fendermint/vm/interpreter/src/chain.rs

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ use crate::{
1616
use anyhow::{anyhow, bail, Context};
1717
use async_stm::atomically;
1818
use async_trait::async_trait;
19-
use fendermint_actor_blobs_shared::params::{GetBlobStatusParams, GetPendingBlobsParams};
20-
use fendermint_actor_blobs_shared::state::BlobStatus;
21-
use fendermint_actor_blobs_shared::Method::DebitAccounts;
19+
use fendermint_actor_blobs_shared::params::{GetBlobStatusParams, GetPendingBlobsParams, UpdatePowerTableParams};
20+
use fendermint_actor_blobs_shared::state::{BlobStatus, Power, PowerTable, Validator};
21+
use fendermint_actor_blobs_shared::Method::{DebitAccounts, UpdatePowerTable};
2222
use fendermint_actor_blobs_shared::{
2323
params::FinalizeBlobParams,
2424
Method::{FinalizeBlob, GetBlobStatus, GetPendingBlobs},
@@ -43,7 +43,7 @@ use fendermint_vm_topdown::{
4343
};
4444
use fvm_ipld_blockstore::Blockstore;
4545
use fvm_ipld_encoding::RawBytes;
46-
use fvm_shared::address::Address;
46+
use fvm_shared::address::{Address, Error};
4747
use fvm_shared::clock::ChainEpoch;
4848
use fvm_shared::econ::TokenAmount;
4949
use fvm_shared::message::Message;
@@ -584,6 +584,41 @@ where
584584
let proposer = state.validator_id().map(|id| id.to_string());
585585
let proposer_ref = proposer.as_deref();
586586

587+
let (_configuration_number, powers) = self.gateway_caller.current_power_table(&mut state)?;
588+
let power_table = PowerTable(powers.iter().filter_map(|validator| {
589+
let public_key = validator.public_key.0.serialize();
590+
let address = Address::new_secp256k1(&public_key);
591+
match address {
592+
Ok(address) => {
593+
let validator = Validator {
594+
power: Power(validator.power.0),
595+
address,
596+
};
597+
Some(validator)
598+
}
599+
Err(_) => {
600+
tracing::debug!(
601+
"can not construct secp256k1 address from public key"
602+
);
603+
None
604+
}
605+
}
606+
}).collect());
607+
let params = RawBytes::serialize(UpdatePowerTableParams(power_table))?;
608+
let msg = Message {
609+
version: Default::default(),
610+
from: system::SYSTEM_ACTOR_ADDR,
611+
to: blobs::BLOBS_ACTOR_ADDR,
612+
sequence: 0,
613+
value: Default::default(),
614+
method_num: UpdatePowerTable as u64,
615+
params: params,
616+
gas_limit: fvm_shared::BLOCK_GAS_LIMIT,
617+
gas_fee_cap: Default::default(),
618+
gas_premium: Default::default(),
619+
};
620+
state.execute_implicit(msg)?;
621+
587622
atomically(|| {
588623
env.parent_finality_provider
589624
.set_new_finality(finality.clone(), prev_finality.clone())?;
@@ -731,6 +766,9 @@ where
731766
) -> anyhow::Result<(Self::State, Self::EndOutput)> {
732767
let (mut state, out) = self.inner.end(state).await?;
733768

769+
// TODO SU Wrong
770+
let a = self.gateway_caller.current_power_table(&mut state);
771+
734772
// Update any component that needs to know about changes in the power table.
735773
if !out.0.is_empty() {
736774
let power_updates = out

0 commit comments

Comments
 (0)