Skip to content

Commit 45e2500

Browse files
authored
Add currentCommittee to the faucet; use it in wallet init. (#4457)
## Motivation In #4437 I used the existing `currentValidators` faucet query in `wallet init` and then made the client synchronize the initial admin chain from a committee where all these validators have the same weight. ## Proposal Add a `currentCommittee` query that returns the actual current committee, and use that to synchronize. ## Test Plan The reconfiguration test exercises this. ## Release Plan - These changes should be backported to devnet and testnet, published in an SDK and deployed in the faucet. ## Links - Closes #4434. - [reviewer checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist)
1 parent 1dbb107 commit 45e2500

File tree

9 files changed

+61
-156
lines changed

9 files changed

+61
-156
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

linera-execution/src/committee.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use std::{borrow::Cow, collections::BTreeMap, str::FromStr};
66

7-
use async_graphql::InputObject;
87
use linera_base::crypto::{AccountPublicKey, CryptoError, ValidatorPublicKey};
98
use serde::{Deserialize, Serialize};
109

@@ -59,7 +58,8 @@ pub struct ValidatorState {
5958
}
6059

6160
/// A set of validators (identified by their public keys) and their voting rights.
62-
#[derive(Eq, PartialEq, Hash, Clone, Debug, Default, InputObject)]
61+
#[derive(Eq, PartialEq, Hash, Clone, Debug, Default)]
62+
#[cfg_attr(with_graphql, derive(async_graphql::InputObject))]
6363
pub struct Committee {
6464
/// The validators in the committee.
6565
pub validators: BTreeMap<ValidatorPublicKey, ValidatorState>,

linera-execution/src/graphql.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,19 @@ use linera_views::{context::Context, map_view::MapView};
1414

1515
use crate::{
1616
committee::{Committee, ValidatorState},
17+
policy::ResourceControlPolicy,
1718
system::UserData,
1819
ExecutionStateView, SystemExecutionStateView,
1920
};
2021

2122
doc_scalar!(UserData, "Optional user message attached to a transfer");
2223

24+
async_graphql::scalar!(
25+
ResourceControlPolicy,
26+
"ResourceControlPolicyScalar",
27+
"A collection of prices and limits associated with block execution"
28+
);
29+
2330
#[async_graphql::Object(cache_control(no_cache))]
2431
impl Committee {
2532
#[graphql(derived(name = "validators"))]
@@ -41,6 +48,11 @@ impl Committee {
4148
async fn _validity_threshold(&self) -> u64 {
4249
self.validity_threshold()
4350
}
51+
52+
#[graphql(derived(name = "policy"))]
53+
async fn _policy(&self) -> &ResourceControlPolicy {
54+
self.policy()
55+
}
4456
}
4557

4658
#[async_graphql::Object(cache_control(no_cache))]

linera-execution/src/policy.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
1212
use std::{collections::BTreeSet, fmt};
1313

14-
use async_graphql::InputObject;
1514
use linera_base::{
1615
data_types::{Amount, ArithmeticError, BlobContent, CompressedBytecode, Resources},
1716
ensure,
@@ -23,7 +22,7 @@ use serde::{Deserialize, Serialize};
2322
use crate::ExecutionError;
2423

2524
/// A collection of prices and limits associated with block execution.
26-
#[derive(Eq, PartialEq, Hash, Clone, Debug, Serialize, Deserialize, InputObject)]
25+
#[derive(Eq, PartialEq, Hash, Clone, Debug, Serialize, Deserialize)]
2726
pub struct ResourceControlPolicy {
2827
/// The price per unit of fuel (aka gas) for Wasm execution.
2928
pub wasm_fuel_unit: Amount,

linera-faucet/client/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ edition.workspace = true
1414
[dependencies]
1515
linera-base.workspace = true
1616
linera-client.workspace = true
17+
linera-execution.workspace = true
1718
linera-version.workspace = true
1819
reqwest.workspace = true
1920
serde.workspace = true

linera-faucet/client/src/lib.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
66
// TODO(#3362): generate this code
77

8+
use std::collections::BTreeMap;
9+
810
use linera_base::{crypto::ValidatorPublicKey, data_types::ChainDescription};
911
use linera_client::config::GenesisConfig;
12+
use linera_execution::{committee::ValidatorState, Committee, ResourceControlPolicy};
1013
use linera_version::VersionInfo;
1114
use thiserror_context::Context;
1215

@@ -137,4 +140,34 @@ impl Faucet {
137140
.map(|validator| (validator.public_key, validator.network_address))
138141
.collect())
139142
}
143+
144+
pub async fn current_committee(&self) -> Result<Committee, Error> {
145+
#[derive(serde::Deserialize)]
146+
struct CommitteeResponse {
147+
validators: BTreeMap<ValidatorPublicKey, ValidatorState>,
148+
policy: ResourceControlPolicy,
149+
}
150+
151+
#[derive(serde::Deserialize)]
152+
#[serde(rename_all = "camelCase")]
153+
struct Response {
154+
current_committee: CommitteeResponse,
155+
}
156+
157+
let response = self
158+
.query::<Response>(
159+
"query { currentCommittee { \
160+
validators \
161+
policy \
162+
} }",
163+
)
164+
.await?;
165+
166+
let committee_response = response.current_committee;
167+
168+
Ok(Committee::new(
169+
committee_response.validators,
170+
committee_response.policy,
171+
))
172+
}
140173
}

linera-faucet/server/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use linera_core::{
3939
};
4040
use linera_execution::{
4141
system::{OpenChainConfig, SystemOperation},
42-
ExecutionError, Operation,
42+
Committee, ExecutionError, Operation,
4343
};
4444
#[cfg(feature = "metrics")]
4545
use linera_metrics::prometheus_server;
@@ -195,6 +195,11 @@ where
195195
})
196196
.collect())
197197
}
198+
199+
/// Returns the current committee, including weights and resource policy.
200+
async fn current_committee(&self) -> Result<Committee, Error> {
201+
Ok(self.client.local_committee().await?)
202+
}
198203
}
199204

200205
#[async_graphql::Object(cache_control(no_cache))]

linera-service-graphql-client/gql/service_schema.graphql

Lines changed: 3 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ input Committee {
450450
"""
451451
The policy agreed on for this epoch.
452452
"""
453-
policy: ResourceControlPolicy!
453+
policy: ResourceControlPolicyScalar!
454454
}
455455

456456
type ConfirmedBlock {
@@ -1252,139 +1252,9 @@ type ReentrantCollectionView_ChainId_OutboxStateView_06c2376d {
12521252
}
12531253

12541254
"""
1255-
A collection of prices and limits associated with block execution.
1255+
A collection of prices and limits associated with block execution
12561256
"""
1257-
input ResourceControlPolicy {
1258-
"""
1259-
The price per unit of fuel (aka gas) for Wasm execution.
1260-
"""
1261-
wasmFuelUnit: Amount!
1262-
"""
1263-
The price per unit of fuel (aka gas) for EVM execution.
1264-
"""
1265-
evmFuelUnit: Amount!
1266-
"""
1267-
The price of one read operation.
1268-
"""
1269-
readOperation: Amount!
1270-
"""
1271-
The price of one write operation.
1272-
"""
1273-
writeOperation: Amount!
1274-
"""
1275-
The price of accessing one byte from the runtime.
1276-
"""
1277-
byteRuntime: Amount!
1278-
"""
1279-
The price of reading a byte.
1280-
"""
1281-
byteRead: Amount!
1282-
"""
1283-
The price of writing a byte
1284-
"""
1285-
byteWritten: Amount!
1286-
"""
1287-
The base price to read a blob.
1288-
"""
1289-
blobRead: Amount!
1290-
"""
1291-
The base price to publish a blob.
1292-
"""
1293-
blobPublished: Amount!
1294-
"""
1295-
The price to read a blob, per byte.
1296-
"""
1297-
blobByteRead: Amount!
1298-
"""
1299-
The price to publish a blob, per byte.
1300-
"""
1301-
blobBytePublished: Amount!
1302-
"""
1303-
The price of increasing storage by a byte.
1304-
"""
1305-
byteStored: Amount!
1306-
"""
1307-
The base price of adding an operation to a block.
1308-
"""
1309-
operation: Amount!
1310-
"""
1311-
The additional price for each byte in the argument of a user operation.
1312-
"""
1313-
operationByte: Amount!
1314-
"""
1315-
The base price of sending a message from a block.
1316-
"""
1317-
message: Amount!
1318-
"""
1319-
The additional price for each byte in the argument of a user message.
1320-
"""
1321-
messageByte: Amount!
1322-
"""
1323-
The price per query to a service as an oracle.
1324-
"""
1325-
serviceAsOracleQuery: Amount!
1326-
"""
1327-
The price for a performing an HTTP request.
1328-
"""
1329-
httpRequest: Amount!
1330-
"""
1331-
The maximum amount of Wasm fuel a block can consume.
1332-
"""
1333-
maximumWasmFuelPerBlock: Int!
1334-
"""
1335-
The maximum amount of EVM fuel a block can consume.
1336-
"""
1337-
maximumEvmFuelPerBlock: Int!
1338-
"""
1339-
The maximum time in milliseconds that a block can spend executing services as oracles.
1340-
"""
1341-
maximumServiceOracleExecutionMs: Int!
1342-
"""
1343-
The maximum size of a block. This includes the block proposal itself as well as
1344-
the execution outcome.
1345-
"""
1346-
maximumBlockSize: Int!
1347-
"""
1348-
The maximum size of decompressed contract or service bytecode, in bytes.
1349-
"""
1350-
maximumBytecodeSize: Int!
1351-
"""
1352-
The maximum size of a blob.
1353-
"""
1354-
maximumBlobSize: Int!
1355-
"""
1356-
The maximum number of published blobs per block.
1357-
"""
1358-
maximumPublishedBlobs: Int!
1359-
"""
1360-
The maximum size of a block proposal.
1361-
"""
1362-
maximumBlockProposalSize: Int!
1363-
"""
1364-
The maximum data to read per block
1365-
"""
1366-
maximumBytesReadPerBlock: Int!
1367-
"""
1368-
The maximum data to write per block
1369-
"""
1370-
maximumBytesWrittenPerBlock: Int!
1371-
"""
1372-
The maximum size in bytes of an oracle response.
1373-
"""
1374-
maximumOracleResponseBytes: Int!
1375-
"""
1376-
The maximum size in bytes of a received HTTP response.
1377-
"""
1378-
maximumHttpResponseBytes: Int!
1379-
"""
1380-
The maximum amount of time allowed to wait for an HTTP response.
1381-
"""
1382-
httpRequestTimeoutMs: Int!
1383-
"""
1384-
The list of hosts that contracts and services can send HTTP requests to.
1385-
"""
1386-
httpRequestAllowList: [String!]!
1387-
}
1257+
scalar ResourceControlPolicyScalar
13881258

13891259
"""
13901260
A number to identify successive attempts to decide a value in a consensus protocol.

linera-service/src/cli/main.rs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use chrono::Utc;
1919
use colored::Colorize;
2020
use futures::{lock::Mutex, FutureExt as _, StreamExt};
2121
use linera_base::{
22-
crypto::{AccountPublicKey, InMemorySigner, Signer},
22+
crypto::{InMemorySigner, Signer},
2323
data_types::{ApplicationPermissions, Timestamp},
2424
identifiers::{AccountOwner, ChainId},
2525
listen_for_shutdown_signals,
@@ -1624,24 +1624,8 @@ impl Runnable for Job {
16241624
signer.into_value(),
16251625
);
16261626
let faucet = cli_wrappers::Faucet::new(faucet_url);
1627-
let validators = faucet.current_validators().await?;
1627+
let committee = faucet.current_committee().await?;
16281628
let chain_client = context.make_chain_client(network_description.admin_chain_id);
1629-
// TODO(#4434): This is a quick workaround with an equal-weight committee. Instead,
1630-
// the faucet should provide the full committee including weights.
1631-
let committee = Committee::new(
1632-
validators
1633-
.into_iter()
1634-
.map(|(pub_key, network_address)| {
1635-
let state = ValidatorState {
1636-
network_address,
1637-
votes: 100,
1638-
account_public_key: AccountPublicKey::from_slice(&[0; 33]).unwrap(),
1639-
};
1640-
(pub_key, state)
1641-
})
1642-
.collect(),
1643-
Default::default(), // unused
1644-
);
16451629
chain_client
16461630
.synchronize_chain_state_from_committee(committee)
16471631
.await?;

0 commit comments

Comments
 (0)