Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions fendermint/actors/blobs/shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ num-derive = { workspace = true }
num-traits = { workspace = true }
serde = { workspace = true, features = ["derive"] }

recall_actor_sdk = { path = "../../../../recall/actor_sdk" }
recall_ipld = { path = "../../../../recall/ipld" }

[features]
Expand Down
61 changes: 61 additions & 0 deletions fendermint/actors/blobs/shared/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use fvm_shared::address::Address;
use fvm_shared::bigint::{BigInt, BigUint};
use fvm_shared::clock::ChainEpoch;
use fvm_shared::econ::TokenAmount;
use recall_actor_sdk::to_delegated_address;
use recall_ipld::{hamt, hamt::map::TrackedFlushResult, hamt::MapKey};
use serde::{Deserialize, Serialize};
use std::collections::{HashMap, HashSet};
Expand Down Expand Up @@ -123,6 +124,66 @@ impl Account {
}
}

/// The return type used for Account.
#[derive(Debug, Serialize_tuple, Deserialize_tuple)]
pub struct AccountInfo {
/// Total size of all blobs managed by the account.
pub capacity_used: u64,
/// Current free credit in byte-blocks that can be used for new commitments.
pub credit_free: Credit,
/// Current committed credit in byte-blocks that will be used for debits.
pub credit_committed: Credit,
/// Optional default sponsor account address.
pub credit_sponsor: Option<Address>,
/// The chain epoch of the last debit.
pub last_debit_epoch: ChainEpoch,
/// Credit approvals to other accounts from this account, keyed by receiver.
pub approvals_to: HashMap<Address, CreditApproval>,
/// Credit approvals to this account from other accounts, keyed by sender.
pub approvals_from: HashMap<Address, CreditApproval>,
/// The maximum allowed TTL for actor's blobs.
pub max_ttl: ChainEpoch,
/// The total token value an account has used to buy credits.
pub gas_allowance: TokenAmount,
}

impl AccountInfo {
pub fn from(rt: &impl Runtime, account: Account) -> Result<Self, ActorError> {
let store = rt.store();
let mut approvals_to = HashMap::new();
account
.approvals_to
.hamt(store)?
.for_each(|address, approval| {
let external_account_address = to_delegated_address(rt, address)?;
approvals_to.insert(external_account_address, approval.clone());
Ok(())
})?;

let mut approvals_from = HashMap::new();
account
.approvals_from
.hamt(store)?
.for_each(|address, approval| {
let external_account_address = to_delegated_address(rt, address)?;
approvals_from.insert(external_account_address, approval.clone());
Ok(())
})?;

Ok(AccountInfo {
capacity_used: account.capacity_used,
credit_free: account.credit_free,
credit_committed: account.credit_committed,
credit_sponsor: account.credit_sponsor,
last_debit_epoch: account.last_debit_epoch,
approvals_to,
approvals_from,
max_ttl: account.max_ttl,
gas_allowance: account.gas_allowance,
})
}
}

/// A credit approval from one account to another.
#[derive(Debug, Clone, PartialEq, Serialize_tuple, Deserialize_tuple)]
pub struct CreditApproval {
Expand Down
3 changes: 1 addition & 2 deletions fendermint/actors/blobs/src/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use fendermint_actor_blobs_shared::params::{
use fendermint_actor_blobs_shared::state::{
BlobInfo, BlobRequest, BlobStatus, Credit, CreditApproval, GasAllowance, Hash, Subscription,
};
use fendermint_actor_blobs_shared::Method;
use fendermint_actor_blobs_shared::{state::AccountInfo, Method};
use fendermint_actor_recall_config_shared::{get_config, require_caller_is_admin};
use fil_actors_runtime::{
actor_dispatch, actor_error, extract_send_result,
Expand All @@ -30,7 +30,6 @@ use recall_actor_sdk::{
use crate::sol_facade::credit::{CreditApproved, CreditDebited, CreditPurchased, CreditRevoked};
use crate::sol_facade::gas::{GasSponsorSet, GasSponsorUnset};
use crate::sol_facade::{blobs as sol_blobs, credit as sol_credit, AbiCall, AbiCallRuntime};
use crate::state::AccountInfo;
use crate::{State, BLOBS_ACTOR_NAME};

#[cfg(feature = "fil-actor")]
Expand Down
3 changes: 1 addition & 2 deletions fendermint/actors/blobs/src/sol_facade/credit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use fendermint_actor_blobs_shared::params::{
ApproveCreditParams, BuyCreditParams, GetAccountParams, GetCreditApprovalParams,
RevokeCreditParams, SetAccountStatusParams, SetSponsorParams,
};
use fendermint_actor_blobs_shared::state::{Credit, CreditApproval, TtlStatus};
use fendermint_actor_blobs_shared::state::{AccountInfo, Credit, CreditApproval, TtlStatus};
use fil_actors_runtime::runtime::Runtime;
use fil_actors_runtime::{actor_error, ActorError};
use fvm_shared::address::Address;
Expand All @@ -22,7 +22,6 @@ use std::collections::{HashMap, HashSet};
pub use recall_sol_facade::credit::Calls;

use crate::sol_facade::{AbiCall, AbiCallRuntime, AbiEncodeError};
use crate::state::AccountInfo;

pub struct CreditPurchased {
from: Address,
Expand Down
64 changes: 1 addition & 63 deletions fendermint/actors/blobs/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright 2021-2023 Protocol Labs
// SPDX-License-Identifier: Apache-2.0, MIT

use std::collections::{HashMap, HashSet};
use std::collections::HashSet;
use std::error::Error;
use std::fmt::Display;
use std::str::from_utf8;
Expand Down Expand Up @@ -34,8 +34,6 @@ mod expiries;
use accounts::AccountsState;
use blobs::{BlobsProgressCollection, BlobsState};
use expiries::{ExpiriesState, ExpiryUpdate};
use fil_actors_runtime::runtime::Runtime;
use recall_actor_sdk::to_delegated_address;

/// The state represents all accounts and stored blobs.
#[derive(Debug, Serialize_tuple, Deserialize_tuple)]
Expand Down Expand Up @@ -1801,66 +1799,6 @@ fn ensure_gas_limit(
Ok(())
}

/// The return type used for Account.
#[derive(Debug, Serialize_tuple, Deserialize_tuple)]
pub struct AccountInfo {
/// Total size of all blobs managed by the account.
pub capacity_used: u64,
/// Current free credit in byte-blocks that can be used for new commitments.
pub credit_free: Credit,
/// Current committed credit in byte-blocks that will be used for debits.
pub credit_committed: Credit,
/// Optional default sponsor account address.
pub credit_sponsor: Option<Address>,
/// The chain epoch of the last debit.
pub last_debit_epoch: ChainEpoch,
/// Credit approvals to other accounts from this account, keyed by receiver.
pub approvals_to: HashMap<Address, CreditApproval>,
/// Credit approvals to this account from other accounts, keyed by sender.
pub approvals_from: HashMap<Address, CreditApproval>,
/// The maximum allowed TTL for actor's blobs.
pub max_ttl: ChainEpoch,
/// The total token value an account has used to buy credits.
pub gas_allowance: TokenAmount,
}

impl AccountInfo {
pub fn from(rt: &impl Runtime, account: Account) -> Result<Self, ActorError> {
let store = rt.store();
let mut approvals_to = HashMap::new();
account
.approvals_to
.hamt(store)?
.for_each(|address, approval| {
let external_account_address = to_delegated_address(rt, address)?;
approvals_to.insert(external_account_address, approval.clone());
Ok(())
})?;

let mut approvals_from = HashMap::new();
account
.approvals_from
.hamt(store)?
.for_each(|address, approval| {
let external_account_address = to_delegated_address(rt, address)?;
approvals_from.insert(external_account_address, approval.clone());
Ok(())
})?;

Ok(AccountInfo {
capacity_used: account.capacity_used,
credit_free: account.credit_free,
credit_committed: account.credit_committed,
credit_sponsor: account.credit_sponsor,
last_debit_epoch: account.last_debit_epoch,
approvals_to,
approvals_from,
max_ttl: account.max_ttl,
gas_allowance: account.gas_allowance,
})
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
4 changes: 2 additions & 2 deletions recall/ipld/src/hamt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
mod core;
pub mod map;

pub use core::DEFAULT_HAMT_CONFIG;
pub use core::MapKey;
pub use core::Map;
pub use core::MapKey;
pub use core::DEFAULT_HAMT_CONFIG;
pub use fvm_ipld_hamt::{BytesKey, Error};
pub use map::Root;
Loading