Skip to content

Commit bca44a6

Browse files
committed
Merge remote-tracking branch 'origin/main' into stevan/sim-readme
Signed-off-by: Stevan A <stevana@users.noreply.github.com>
2 parents e67ecfb + 8cc6d30 commit bca44a6

36 files changed

Lines changed: 3424 additions & 583 deletions

File tree

.github/workflows/CI.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,6 @@ jobs:
161161
name: Snapshots
162162
runs-on: ubuntu-latest
163163
if: ${{ !github.event.pull_request.draft }}
164-
env:
165-
AMARU_PEER_ADDRESS: 127.0.0.1:3001
166164
strategy:
167165
matrix:
168166
network:

Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,11 @@ debug = true
148148
[profile.release]
149149
lto = true
150150
codegen-units = 1
151+
152+
[workspace.metadata.cross.target.aarch64-unknown-linux-musl]
153+
pre-build = [
154+
"apt update",
155+
"apt install -y libclang-dev"
156+
]
157+
[workspace.metadata.cross.target.aarch64-unknown-linux-musl.env]
158+
passthrough = ["LIBCLANG_PATH=/usr/lib/llvm-10/lib"]

Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ DATA_FOLDER := $(CONFIG_FOLDER)/$(NETWORK)
44
SNAPSHOTS_FILE := $(DATA_FOLDER)/snapshots.json
55
NONCES_FILE := $(DATA_FOLDER)/nonces.json
66
HEADERS_FILE := $(DATA_FOLDER)/headers.json
7-
AMARU_PEER_ADDRESS ?= 127.0.0.1:3001
7+
PEER_ADDRESS ?= 127.0.0.1:3001
88
HASKELL_NODE_CONFIG_DIR ?= cardano-node-config
99
DEMO_TARGET_EPOCH ?= 182
1010
HASKELL_NODE_CONFIG_SOURCE := https://book.world.dev.cardano.org/environments
@@ -46,14 +46,14 @@ import-snapshots: snapshots/$(NETWORK) ## Import snapshots for demo
4646
--ledger-dir "$(LEDGER_DIR)" \
4747
$$SNAPSHOT_ARGS
4848

49-
import-headers: ## Import headers from $AMARU_PEER_ADDRESS for demo
49+
import-headers: ## Import headers from $PEER_ADDRESS for demo
5050
@if [ ! -f "$(HEADERS_FILE)" ]; then echo "HEADERS_FILE not found: $(HEADERS_FILE)"; exit 1; fi; \
5151
HEADERS=$$(jq -r '.[]' $(HEADERS_FILE)); \
5252
for HEADER in $$HEADERS; do \
5353
cargo run --profile $(BUILD_PROFILE) -- import-headers \
5454
--network $(NETWORK) \
5555
--chain-dir $(CHAIN_DIR) \
56-
--peer-address $(AMARU_PEER_ADDRESS) \
56+
--peer-address $(PEER_ADDRESS) \
5757
--starting-point $$HEADER \
5858
--count 2; \
5959
done
@@ -83,7 +83,7 @@ clear-dbs: ## Clear the databases
8383

8484
bootstrap: clear-dbs ## Bootstrap the node from scratch
8585
cargo run --profile $(BUILD_PROFILE) -- bootstrap \
86-
--peer-address $(AMARU_PEER_ADDRESS) \
86+
--peer-address $(PEER_ADDRESS) \
8787
--config-dir $(CONFIG_FOLDER) \
8888
--ledger-dir $(LEDGER_DIR) \
8989
--chain-dir $(CHAIN_DIR) \
@@ -93,7 +93,7 @@ dev: ## Compile and run for development with default options
9393
cargo run --profile $(BUILD_PROFILE) -- daemon \
9494
--ledger-dir $(LEDGER_DIR) \
9595
--chain-dir $(CHAIN_DIR) \
96-
--peer-address $(AMARU_PEER_ADDRESS) \
96+
--peer-address $(PEER_ADDRESS) \
9797
--network=$(NETWORK) \
9898
--listen-address $(LISTEN_ADDRESS)
9999

@@ -125,7 +125,7 @@ coverage-lconv: ## Run test coverage for CI to upload to Codecov
125125

126126
demo: ## Synchronize Amaru until a target epoch $DEMO_TARGET_EPOCH
127127
LEDGER_DIR=$(LEDGER_DIR) CHAIN_DIR=$(CHAIN_DIR) \
128-
./scripts/demo $(BUILD_PROFILE) $(AMARU_PEER_ADDRESS) $(LISTEN_ADDRESS) $(DEMO_TARGET_EPOCH) $(NETWORK)
128+
./scripts/demo $(BUILD_PROFILE) $(PEER_ADDRESS) $(LISTEN_ADDRESS) $(DEMO_TARGET_EPOCH) $(NETWORK)
129129

130130
build-examples: ## Build all examples
131131
@for dir in $(wildcard examples/*/.); do \

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ cargo build --release
2323
on the [preprod](https://book.world.dev.cardano.org/env-preprod.html) network.
2424
>
2525
> To run a local peer, refer to [Cardano's developers portal](https://developers.cardano.org/docs/get-started/cardano-node/running-cardano).
26-
> Make sure your peer listens to port `3001` or adapt the `AMARU_PEER_ADDRESS` environment variable (e.g. `export AMARU_PEER_ADDRESS=127.0.0.1:3002`)
26+
> Make sure your peer listens to port `3001` or adapt the `PEER_ADDRESS` environment variable (e.g. `export PEER_ADDRESS=127.0.0.1:3002`)
2727
2828
1. Bootstrap the node:
2929

crates/amaru-kernel/src/lib.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ use pallas_primitives::{
3333
MintedPostAlonzoTransactionOutput, NativeScript, PseudoDatumOption, RedeemerTag,
3434
RedeemersValue,
3535
},
36-
PlutusScript,
3736
};
3837
use sha3::{Digest as _, Sha3_256};
3938
use std::{
@@ -47,10 +46,13 @@ use std::{
4746
};
4847

4948
pub use memoized::*;
50-
pub use pallas_addresses::{byron::AddrType, Address, Network, StakeAddress, StakePayload};
49+
pub use pallas_addresses::{
50+
byron::AddrType, Address, Network, ShelleyAddress, ShelleyDelegationPart, ShelleyPaymentPart,
51+
StakeAddress, StakePayload,
52+
};
5153
pub use pallas_codec::{
5254
minicbor as cbor,
53-
utils::{Bytes, CborWrap, KeyValuePairs, NonEmptyKeyValuePairs, Nullable, Set},
55+
utils::{Bytes, CborWrap, Int, KeyValuePairs, NonEmptyKeyValuePairs, Nullable, Set},
5456
};
5557
pub use pallas_crypto::{
5658
hash::{Hash, Hasher},
@@ -71,7 +73,8 @@ pub use pallas_primitives::{
7173
TransactionOutput, Tx, UnitInterval, VKeyWitness, Value, Voter, VotingProcedure,
7274
VotingProcedures, VrfKeyhash, WitnessSet,
7375
},
74-
AssetName, Constr, DatumHash, MaybeIndefArray, PlutusData,
76+
AssetName, BigInt, Constr, DatumHash, MaybeIndefArray, PlutusData, PlutusScript, PolicyId,
77+
PositiveCoin,
7578
};
7679
pub use pallas_traverse::{ComputeHash, OriginalHash};
7780
pub use serde_json as json;
@@ -774,7 +777,7 @@ pub fn new_stake_address(network: Network, payload: StakePayload) -> StakeAddres
774777
// ProposalId
775778
// ----------------------------------------------------------------------------
776779

777-
#[derive(Debug, Eq, PartialEq)]
780+
#[derive(Debug, Eq, PartialEq, Clone)]
778781
// TODO: This type shouldn't exist, and `Ord` / `PartialOrd` should be derived in Pallas on
779782
// 'GovActionId' already.
780783
pub struct ComparableProposalId {

crates/amaru-kernel/src/memoized/plutus_data.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
use crate::{cbor, memoized::blanket_try_from_hex_bytes, Bytes, Hash, Hasher, KeepRaw, PlutusData};
16+
use pallas_codec::minicbor;
1617

1718
#[derive(Debug, Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
1819
#[serde(try_from = "&str")]
@@ -26,6 +27,16 @@ pub struct MemoizedPlutusData {
2627
}
2728

2829
impl MemoizedPlutusData {
30+
pub fn new(data: PlutusData) -> Result<Self, String> {
31+
let mut buf = Vec::new();
32+
minicbor::encode(&data, &mut buf).map_err(|_| "failed to encode PlutusData".to_string())?;
33+
34+
Ok(Self {
35+
original_bytes: Bytes::from(buf),
36+
data,
37+
})
38+
}
39+
2940
pub fn original_bytes(&self) -> &[u8] {
3041
&self.original_bytes
3142
}

crates/amaru-kernel/src/memoized/transaction_output.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ use crate::{
2020
Value,
2121
};
2222

23-
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
23+
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, PartialEq)]
2424
pub struct MemoizedTransactionOutput {
2525
#[serde(skip)]
26-
is_legacy: bool,
26+
pub is_legacy: bool,
2727

2828
#[serde(serialize_with = "serialize_address")]
2929
#[serde(deserialize_with = "deserialize_address")]

crates/amaru-ledger/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ homepage.workspace = true
1212
documentation.workspace = true
1313
rust-version.workspace = true
1414

15+
[features]
16+
default = []
17+
test-utils = ["proptest", "slot-arithmetic/test-utils"]
18+
1519
[dependencies]
1620
hex.workspace = true
1721
num.workspace = true
@@ -26,9 +30,9 @@ iter-borrow.workspace = true
2630
progress-bar.workspace = true
2731
slot-arithmetic.workspace = true
2832
tracing-json.workspace = true
33+
proptest = { workspace = true, features = ["std"], optional = true }
2934

3035
[dev-dependencies]
31-
proptest = { workspace = true, features = [ "std" ] }
3236
slot-arithmetic = { workspace = true, features = [ "test-utils" ] }
3337
test-case.workspace = true
3438

crates/amaru-ledger/src/store.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
// limitations under the License.
1414

1515
pub mod columns;
16-
pub mod in_memory;
1716

1817
use crate::summary::Pots;
1918
use amaru_kernel::MemoizedTransactionOutput;
@@ -118,6 +117,10 @@ pub trait Snapshot: ReadStore {
118117
}
119118

120119
pub trait Store: ReadStore {
120+
type Transaction<'a>: TransactionalContext<'a>
121+
where
122+
Self: 'a;
123+
121124
/// Construct and save on-disk a snapshot of the store. The epoch number is used when
122125
/// there's no existing snapshot and, to ensure that snapshots are taken in order.
123126
///
@@ -130,7 +133,7 @@ pub trait Store: ReadStore {
130133
fn next_snapshot(&self, epoch: Epoch) -> Result<(), StoreError>;
131134

132135
/// Create a new transaction context. This is used to perform updates on the store.
133-
fn create_transaction(&self) -> impl TransactionalContext<'_>;
136+
fn create_transaction(&self) -> Self::Transaction<'_>;
134137

135138
/// Access the tip of the stable store, corresponding to the latest point that was saved.
136139
fn tip(&self) -> Result<Point, StoreError>;
@@ -166,7 +169,7 @@ pub trait HistoricalStores {
166169
fn for_epoch(&self, epoch: Epoch) -> Result<impl Snapshot, StoreError>;
167170
}
168171

169-
#[derive(Debug, PartialEq, Eq, minicbor::Encode, minicbor::Decode)]
172+
#[derive(Debug, PartialEq, Eq, minicbor::Encode, minicbor::Decode, Clone)]
170173
pub enum EpochTransitionProgress {
171174
#[n(0)]
172175
EpochEnded,
@@ -302,3 +305,23 @@ impl<U, P, A, D, C, PP> Default
302305
}
303306
}
304307
}
308+
309+
impl<U, P, A, D, C, PP> Columns<U, P, A, D, C, PP> {
310+
pub fn empty() -> Columns<
311+
std::iter::Empty<U>,
312+
std::iter::Empty<P>,
313+
std::iter::Empty<A>,
314+
std::iter::Empty<D>,
315+
std::iter::Empty<C>,
316+
std::iter::Empty<PP>,
317+
> {
318+
Columns {
319+
utxo: std::iter::empty(),
320+
pools: std::iter::empty(),
321+
accounts: std::iter::empty(),
322+
dreps: std::iter::empty(),
323+
cc_members: std::iter::empty(),
324+
proposals: std::iter::empty(),
325+
}
326+
}
327+
}

crates/amaru-ledger/src/store/columns/accounts.rs

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -80,35 +80,22 @@ impl<'a, C> cbor::decode::Decode<'a, C> for Row {
8080
})
8181
}
8282
}
83-
84-
#[cfg(test)]
85-
pub(crate) mod test {
86-
use super::Row;
83+
#[cfg(any(test, feature = "test-utils"))]
84+
pub mod tests {
85+
use super::*;
8786
use crate::store::columns::{dreps::tests::any_certificate_pointer, pools::tests::any_pool_id};
88-
use amaru_kernel::{prop_cbor_roundtrip, DRep, Hash, Lovelace, StakeCredential};
89-
use proptest::{option, prelude::*};
90-
91-
prop_cbor_roundtrip!(Row, any_row());
87+
use amaru_kernel::{prop_cbor_roundtrip, Hash};
88+
use proptest::{option, prelude::*, prop_compose};
9289

93-
prop_compose! {
94-
fn any_row()(
95-
delegatee in option::of(any_pool_id()),
96-
deposit in any::<Lovelace>(),
97-
drep in option::of(any_drep()),
98-
drep_registered_at in any_certificate_pointer(),
99-
rewards in any::<Lovelace>(),
100-
) -> Row {
101-
Row {
102-
delegatee,
103-
deposit,
104-
drep: drep.map(|drep| (drep, drep_registered_at)),
105-
rewards,
106-
}
107-
}
90+
pub fn any_stake_credential() -> impl Strategy<Value = StakeCredential> {
91+
prop_oneof![
92+
any::<[u8; 28]>().prop_map(|hash| StakeCredential::AddrKeyhash(Hash::new(hash))),
93+
any::<[u8; 28]>().prop_map(|hash| StakeCredential::ScriptHash(Hash::new(hash))),
94+
]
10895
}
10996

11097
prop_compose! {
111-
pub(crate) fn any_drep()(
98+
pub fn any_drep()(
11299
credential in any::<[u8; 28]>(),
113100
kind in any::<u8>(),
114101
) -> DRep {
@@ -120,14 +107,25 @@ pub(crate) mod test {
120107
3 => DRep::NoConfidence,
121108
_ => unreachable!("% 4")
122109
}
123-
124110
}
125111
}
126112

127-
pub(crate) fn any_stake_credential() -> impl Strategy<Value = StakeCredential> {
128-
prop_oneof![
129-
any::<[u8; 28]>().prop_map(|hash| StakeCredential::AddrKeyhash(Hash::new(hash))),
130-
any::<[u8; 28]>().prop_map(|hash| StakeCredential::ScriptHash(Hash::new(hash))),
131-
]
113+
prop_compose! {
114+
pub fn any_row()(
115+
delegatee in option::of(any_pool_id()),
116+
deposit in any::<Lovelace>(),
117+
drep in option::of(any_drep()),
118+
drep_registered_at in any_certificate_pointer(),
119+
rewards in any::<Lovelace>(),
120+
) -> Row {
121+
Row {
122+
delegatee,
123+
deposit,
124+
drep: drep.map(|drep| (drep, drep_registered_at)),
125+
rewards,
126+
}
127+
}
132128
}
129+
130+
prop_cbor_roundtrip!(Row, any_row());
133131
}

0 commit comments

Comments
 (0)