DDC v2 Smart Contracts -- Orchestrate the network around Clusters and Buckets
fn bucket_create(
bucket_params: BucketParams,
cluster_id: ClusterId,
) -> BucketId
Create a new Bucket and return its bucket_id
.
The caller will be its first owner and payer of resources.
bucket_params
is configuration used by clients and nodes. See the data structure of BucketParams
The Bucket can be connected to a single Cluster (currently). Allocate Cluster resources with the function bucket_alloc_into_cluster
fn bucket_alloc_into_cluster(
bucket_id: BucketId,
resource: Resource,
)
Allocate some resources of a Cluster to a Bucket.
The amount of resources is given per vnode (total resources will be resource
times the number of vnodes).
fn bucket_settle_payment(
bucket_id: BucketId,
)
Settle the due costs of a Bucket from its payer account to the Cluster account.
fn bucket_change_params(
bucket_id: BucketId,
params: BucketParams,
)
Change the bucket_params
, which is the configuration used by clients and nodes.
See the data structure of BucketParams
fn bucket_get(
bucket_id: BucketId,
) -> Result
Get the current status of a Bucket.
fn bucket_list(
offset: u32,
limit: u32,
filter_owner_id: Option,
)
Iterate through all Buckets.
The algorithm for paging is: start with offset = 1
and limit = 20
. The function returns a (results, max_id)
. Call again with offset += limit
, until offset >= max_id
. The optimal limit
depends on the size of params.
The results can be filtered by owner. Note that paging must still be completed fully.
fn cluster_create(
_unused: AccountId,
vnode_count: u32,
node_ids: Vec,
cluster_params: ClusterParams,
) -> ClusterId
Create a new Cluster and return its cluster_id
.
The caller will be its first manager.
The Cluster is split in a number of vnodes. The vnodes are assigned to the given physical nodes in a round-robin. Only nodes of providers that trust the Cluster manager can be used (see node_trust_manager
). The assignment can be changed with the function cluster_replace_node
.
cluster_params
is configuration used by clients and nodes. In particular, this describes the semantics of vnodes. See the data structure of ClusterParams
fn cluster_reserve_resource(
cluster_id: ClusterId,
amount: Resource,
)
As manager, reserve more resources for the Cluster from the free capacity of nodes.
The amount of resources is given per vnode (total resources will be resource
times the number of vnodes).
fn cluster_replace_node(
cluster_id: ClusterId,
vnode_i: VNodeIndex,
new_node_id: NodeId,
)
As manager, re-assign a vnode to another physical node.
Only nodes of Providers that trust the Cluster manager can be used (see node_trust_manager
).
fn cluster_distribute_revenues(
cluster_id: ClusterId,
)
Trigger the distribution of revenues from the Cluster to the Providers.
fn cluster_change_params(
cluster_id: ClusterId,
params: ClusterParams,
)
Change the cluster_params
, which is configuration used by clients and nodes.
See the data structure of ClusterParams
fn cluster_get(
cluster_id: ClusterId,
) -> Result
Get the current status of a Cluster.
fn cluster_list(
offset: u32,
limit: u32,
filter_manager_id: Option,
)
Iterate through all Clusters.
The algorithm for paging is: start with offset = 1
and limit = 20
. The function returns a (results, max_id)
. Call again with offset += limit
, until offset >= max_id
. The optimal limit
depends on the size of params.
The results can be filtered by manager. Note that paging must still be completed fully.
fn node_trust_manager(
manager: AccountId,
)
As node Provider, authorize a Cluster manager to use their nodes.
fn node_distrust_manager(
manager: AccountId,
)
As node Provider, revoke the authorization of a Cluster manager to use their nodes.
fn node_create(
rent_per_month: Balance,
node_params: NodeParams,
capacity: Resource,
) -> NodeId
Create a new node and return its node_id
.
The caller will be its owner.
node_params
is configuration used by clients and nodes. In particular, this contains the URL to the service. See the data structure of NodeParams
fn node_change_params(
node_id: NodeId,
params: NodeParams,
)
Change the node_params
, which is configuration used by clients and nodes.
See the data structure of NodeParams
fn node_get(
node_id: NodeId,
) -> Result
Get the current status of a node.
fn node_list(
offset: u32,
limit: u32,
filter_provider_id: Option,
)
Iterate through all nodes.
The algorithm for paging is: start with offset = 1
and limit = 20
. The function returns a (results, max_id)
. Call again with offset += limit
, until offset >= max_id
. The optimal limit
depends on the size of params.
The results can be filtered by owner. Note that paging must still be completed fully.
fn account_deposit(
)
As user, deposit tokens on the account of the caller from the transaction value. This deposit can be used to pay for the services to Buckets of the account.
fn account_get(
account_id: AccountId,
) -> Result
Get the current status of an account.
fn account_get_usd_per_cere(
) -> Balance
Get the current conversion rate between the native currency and an external currency (USD).
fn account_set_usd_per_cere(
usd_per_cere: Balance,
)
As price oracle, set the current conversion rate between the native currency and an external currency (USD).
fn has_permission(
grantee: AccountId,
permission: Permission,
) -> bool
Check whether the given account has the given permission currently.
fn admin_grant_permission(
grantee: AccountId,
permission: Permission,
)
As admin, grant any permission to any account.
fn admin_revoke_permission(
grantee: AccountId,
permission: Permission,
)
As admin, revoke any permission to any account.
fn admin_withdraw(
amount: Balance,
)
As admin, withdraw the funds held in custody in this contract.
This is a temporary measure to allow migrating the funds to a new version of the contract.
fn admin_set_fee_config(
config: FeeConfig,
)
Set the network and Cluster fee configuration.
event BucketCreated(
bucket_id: BucketId, (indexed)
owner_id: AccountId, (indexed)
)
A Bucket was created. The given account is its first owner and payer of resources.
event BucketAllocated(
bucket_id: BucketId, (indexed)
cluster_id: ClusterId, (indexed)
resource: Resource,
)
Some amount of resources of a Cluster were allocated to a Bucket.
event BucketSettlePayment(
bucket_id: BucketId, (indexed)
cluster_id: ClusterId, (indexed)
)
The due costs of a Bucket was settled from the Bucket payer to the Cluster.
event ClusterCreated(
cluster_id: ClusterId, (indexed)
manager: AccountId, (indexed)
cluster_params: ClusterParams,
)
A new Cluster was created.
event ClusterNodeReplaced(
cluster_id: ClusterId, (indexed)
node_id: NodeId, (indexed)
vnode_index: VNodeIndex,
)
A vnode was re-assigned to new node.
event ClusterReserveResource(
cluster_id: ClusterId, (indexed)
resource: Resource,
)
Some resources were reserved for the Cluster from the nodes.
event ClusterDistributeRevenues(
cluster_id: ClusterId, (indexed)
provider_id: AccountId, (indexed)
)
The share of revenues of a Cluster for a Provider was distributed.
event NodeCreated(
node_id: NodeId, (indexed)
provider_id: AccountId, (indexed)
rent_per_month: Balance,
node_params: NodeParams,
)
A node was created. The given account is its owner and recipient of revenues.
event Deposit(
account_id: AccountId, (indexed)
value: Balance,
)
Tokens were deposited on an account.
event GrantPermission(
account_id: AccountId, (indexed)
permission: Permission,
)
A permission was granted to the account.
event RevokePermission(
account_id: AccountId, (indexed)
permission: Permission,
)
A permission was revoked from the account.
fn new(
)
Create a new contract.
The caller will be admin of the contract.
struct {
owner_id: AccountId
cluster_id: ClusterId
flow: Flow
resource_reserved: Resource
}
struct {
: [u8; 32]
}
struct {
from: AccountId
schedule: Schedule
}
struct {
rate: Balance
offset: Balance
}
struct {
manager_id: AccountId
vnodes: Vec<NodeId>
resource_per_vnode: Resource
resource_used: Resource
revenues: Cash
total_rent: Balance
}
struct {
value: Balance
}
struct {
provider_id: ProviderId
rent_per_month: Balance
free_resource: Resource
}
struct {
last_vacant: Index
len: u32
len_entries: u32
}
struct {
next: Index
prev: Index
}
struct {
value: V
key_index: KeyIndex
}
struct {
deposit: Cash
payable_schedule: Schedule
}
struct {
value: V
key_index: KeyIndex
}
struct {
bucket_id: BucketId
bucket: BucketInStatus
params: BucketParams
writer_ids: Vec<AccountId>
rent_covered_until_ms: u64
}
struct {
owner_id: AccountId
cluster_id: ClusterId
resource_reserved: Resource
}
struct {
cluster_id: ClusterId
cluster: Cluster
params: Params
}
struct {
node_id: NodeId
node: Node
params: Params
}
struct {
network_fee_bp: BasisPoints
network_fee_destination: AccountId
cluster_management_fee_bp: BasisPoints
}