Skip to content

Commit 5c001db

Browse files
authored
Merge pull request #510 from EspressoSystems/tw/max-transaction-size
Ensure certified blocks fit into transaction.
2 parents 90fdfe4 + 475a0c9 commit 5c001db

File tree

33 files changed

+341
-175
lines changed

33 files changed

+341
-175
lines changed

adapters/src/bytes.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::convert::Infallible;
22

33
use bytes::{Bytes, BytesMut};
4+
use minicbor::CborLen;
45
use minicbor::decode::{Decoder, Error as DecodeError};
56
use minicbor::encode::{Encoder, Error as EncodeError, Write};
67

@@ -15,6 +16,11 @@ pub fn decode<'b, C>(d: &mut Decoder<'b>, _: &mut C) -> Result<Bytes, DecodeErro
1516
Ok(Bytes::copy_from_slice(d.bytes()?))
1617
}
1718

19+
pub fn cbor_len<C>(b: &Bytes, c: &mut C) -> usize {
20+
let n = b.len();
21+
n.cbor_len(c) + n
22+
}
23+
1824
/// `BytesWrite` can be used to encode directly into `BytesMut`.
1925
#[derive(Default)]
2026
pub struct BytesWriter(BytesMut);

adapters/src/commitment.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use committable::{Commitment, Committable};
2+
use minicbor::CborLen;
23
use minicbor::decode::{Decoder, Error as DecodeError};
34
use minicbor::encode::{Encoder, Error as EncodeError, Write};
45

@@ -13,7 +14,9 @@ where
1314
W: Write,
1415
D: Committable,
1516
{
16-
e.bytes(d.as_ref())?.ok()
17+
let b: &[u8] = d.as_ref();
18+
debug_assert_eq!(b.len(), LEN);
19+
e.bytes(b)?.ok()
1720
}
1821

1922
pub fn decode<'b, D, C>(d: &mut Decoder<'b>, _: &mut C) -> Result<Commitment<D>, DecodeError>
@@ -26,3 +29,10 @@ where
2629
.map(Commitment::from_raw)
2730
.map_err(|e| DecodeError::custom(e).at(p))
2831
}
32+
33+
pub fn cbor_len<D, C>(_: &Commitment<D>, c: &mut C) -> usize
34+
where
35+
D: Committable,
36+
{
37+
LEN.cbor_len(c) + LEN
38+
}

multisig/src/cert.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,24 @@ use std::{collections::BTreeMap, num::NonZeroUsize};
22

33
use committable::{Commitment, Committable, RawCommitmentBuilder};
44
use constant_time_eq::constant_time_eq;
5-
use minicbor::{Decode, Encode};
5+
use minicbor::{CborLen, Decode, Encode};
66
use serde::{Deserialize, Serialize};
77

88
use crate::{Committee, KeyId, PublicKey, Signature};
99

1010
#[derive(
11-
Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize, Encode, Decode,
11+
Debug,
12+
Clone,
13+
PartialEq,
14+
Eq,
15+
Hash,
16+
PartialOrd,
17+
Ord,
18+
Serialize,
19+
Deserialize,
20+
Encode,
21+
Decode,
22+
CborLen,
1223
)]
1324
#[cbor(map)]
1425
pub struct Certificate<D: Committable> {

multisig/src/committee.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::sync::Arc;
55

66
use bimap::BiBTreeMap;
77
use committable::{Commitment, Committable, RawCommitmentBuilder};
8-
use minicbor::{Decode, Encode};
8+
use minicbor::{CborLen, Decode, Encode};
99
use serde::{Deserialize, Serialize};
1010

1111
use super::{KeyId, PublicKey};
@@ -105,7 +105,19 @@ impl Committee {
105105
}
106106

107107
#[derive(
108-
Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, Encode, Decode,
108+
Debug,
109+
Copy,
110+
Clone,
111+
PartialEq,
112+
Eq,
113+
PartialOrd,
114+
Ord,
115+
Hash,
116+
Serialize,
117+
Deserialize,
118+
Encode,
119+
Decode,
120+
CborLen,
109121
)]
110122
#[cbor(transparent)]
111123
#[serde(transparent)]

multisig/src/lib.rs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub mod x25519;
1010
use std::fmt;
1111

1212
use committable::{Commitment, Committable, RawCommitmentBuilder};
13-
use minicbor::{Decode, Encode};
13+
use minicbor::{CborLen, Decode, Encode};
1414
use secp256k1::rand::Rng;
1515
use serde::{Deserialize, Serialize};
1616

@@ -21,7 +21,19 @@ pub use signed::Signed;
2121
pub use votes::VoteAccumulator;
2222

2323
#[derive(
24-
Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, Encode, Decode,
24+
Debug,
25+
Copy,
26+
Clone,
27+
PartialEq,
28+
Eq,
29+
PartialOrd,
30+
Ord,
31+
Hash,
32+
Serialize,
33+
Deserialize,
34+
Encode,
35+
Decode,
36+
CborLen,
2537
)]
2638
#[cbor(transparent)]
2739
#[serde(transparent)]
@@ -85,14 +97,26 @@ pub struct SecretKey {
8597
}
8698

8799
#[derive(
88-
Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, Encode, Decode,
100+
Copy,
101+
Clone,
102+
PartialEq,
103+
Eq,
104+
PartialOrd,
105+
Ord,
106+
Hash,
107+
Serialize,
108+
Deserialize,
109+
Encode,
110+
Decode,
111+
CborLen,
89112
)]
90113
#[cbor(transparent)]
91114
#[serde(transparent)]
92115
pub struct Signature {
93116
#[cbor(
94117
encode_with = "util::encode_secp256k1_sig",
95-
decode_with = "util::decode_secp256k1_sig"
118+
decode_with = "util::decode_secp256k1_sig",
119+
cbor_len = "util::cbor_len_secp256k1_sig"
96120
)]
97121
sig: secp256k1::ecdsa::Signature,
98122
}

multisig/src/util.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::ops::Deref;
22

33
use ed25519_compact::x25519;
4+
use minicbor::CborLen;
45
use minicbor::decode::{Decode, Decoder, Error as DecodeError};
56
use minicbor::encode::{Encoder, Error as EncodeError, Write};
67
use serde::{Deserialize, Deserializer, Serialize, Serializer, de};
@@ -108,6 +109,8 @@ where
108109
}
109110
}
110111

112+
const SECP256K1_SIG_LEN: usize = 64;
113+
111114
pub fn encode_secp256k1_sig<C, W>(
112115
s: &secp256k1::ecdsa::Signature,
113116
e: &mut Encoder<W>,
@@ -116,7 +119,7 @@ pub fn encode_secp256k1_sig<C, W>(
116119
where
117120
W: Write,
118121
{
119-
let a: [u8; 64] = s.serialize_compact();
122+
let a: [u8; SECP256K1_SIG_LEN] = s.serialize_compact();
120123
e.bytes(&a)?;
121124
Ok(())
122125
}
@@ -151,3 +154,7 @@ pub fn decode_secp256k1_pk<'b, C>(
151154
let a: [u8; 33] = minicbor::bytes::ByteArray::<33>::decode(d, c)?.into();
152155
secp256k1::PublicKey::from_byte_array_compressed(a).map_err(|e| DecodeError::custom(e).at(p))
153156
}
157+
158+
pub fn cbor_len_secp256k1_sig<C>(_: &secp256k1::ecdsa::Signature, c: &mut C) -> usize {
159+
SECP256K1_SIG_LEN.cbor_len(c) + SECP256K1_SIG_LEN
160+
}

sailfish-types/src/round.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::fmt;
22
use std::ops::{Add, AddAssign, Deref, Sub};
33

44
use committable::{Commitment, Committable, RawCommitmentBuilder};
5-
use minicbor::{Decode, Encode};
5+
use minicbor::{CborLen, Decode, Encode};
66
use multisig::CommitteeId;
77
use serde::{Deserialize, Serialize};
88

@@ -11,7 +11,19 @@ pub const GENESIS_ROUND: RoundNumber = RoundNumber::new(0);
1111

1212
/// A sailfish round number.
1313
#[derive(
14-
Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, Encode, Decode,
14+
Copy,
15+
Clone,
16+
Debug,
17+
PartialEq,
18+
Eq,
19+
PartialOrd,
20+
Ord,
21+
Hash,
22+
Serialize,
23+
Deserialize,
24+
Encode,
25+
Decode,
26+
CborLen,
1527
)]
1628
#[cbor(transparent)]
1729
#[serde(transparent)]
@@ -117,7 +129,19 @@ impl fmt::Display for RoundNumber {
117129
}
118130

119131
#[derive(
120-
Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, Encode, Decode,
132+
Clone,
133+
Copy,
134+
Debug,
135+
PartialEq,
136+
Eq,
137+
PartialOrd,
138+
Ord,
139+
Hash,
140+
Serialize,
141+
Deserialize,
142+
Encode,
143+
Decode,
144+
CborLen,
121145
)]
122146
#[cbor(map)]
123147
pub struct Round {

test-configs/c0/node_0.toml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ stamp = "/tmp/timeboost.0.stamp"
22

33
[net.public]
44
address = "127.0.0.1:8000"
5-
http_api = "127.0.0.1:8004"
5+
http-api = "127.0.0.1:8004"
66

77
[net.internal]
88
address = "127.0.0.1:8003"
@@ -24,11 +24,12 @@ namespace = 10101
2424

2525
[chain.parent]
2626
id = 31337
27-
rpc_url = "http://127.0.0.1:8545/"
28-
ibox_contract = "0xa0f3a1a4e2b2bcb7b48c8527c28098f207572ec1"
29-
block_tag = "finalized"
30-
key_manager_contract = "0x2bbf15bc655c4cc157b769cfcb1ea9924b9e1a35"
27+
rpc-url = "http://127.0.0.1:8545/"
28+
ibox-contract = "0xa0f3a1a4e2b2bcb7b48c8527c28098f207572ec1"
29+
block-tag = "finalized"
30+
key-manager-contract = "0x2bbf15bc655c4cc157b769cfcb1ea9924b9e1a35"
3131

3232
[espresso]
33-
base_url = "https://query.decaf.testnet.espresso.network/v1/"
34-
websockets_base_url = "wss://query.decaf.testnet.espresso.network/v1/"
33+
base-url = "https://query.decaf.testnet.espresso.network/v1/"
34+
websockets-base-url = "wss://query.decaf.testnet.espresso.network/v1/"
35+
max-transaction-size = 1048576

test-configs/c0/node_1.toml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ stamp = "/tmp/timeboost.1.stamp"
22

33
[net.public]
44
address = "127.0.0.1:8010"
5-
http_api = "127.0.0.1:8014"
5+
http-api = "127.0.0.1:8014"
66

77
[net.internal]
88
address = "127.0.0.1:8013"
@@ -24,11 +24,12 @@ namespace = 10101
2424

2525
[chain.parent]
2626
id = 31337
27-
rpc_url = "http://127.0.0.1:8545/"
28-
ibox_contract = "0xa0f3a1a4e2b2bcb7b48c8527c28098f207572ec1"
29-
block_tag = "finalized"
30-
key_manager_contract = "0x2bbf15bc655c4cc157b769cfcb1ea9924b9e1a35"
27+
rpc-url = "http://127.0.0.1:8545/"
28+
ibox-contract = "0xa0f3a1a4e2b2bcb7b48c8527c28098f207572ec1"
29+
block-tag = "finalized"
30+
key-manager-contract = "0x2bbf15bc655c4cc157b769cfcb1ea9924b9e1a35"
3131

3232
[espresso]
33-
base_url = "https://query.decaf.testnet.espresso.network/v1/"
34-
websockets_base_url = "wss://query.decaf.testnet.espresso.network/v1/"
33+
base-url = "https://query.decaf.testnet.espresso.network/v1/"
34+
websockets-base-url = "wss://query.decaf.testnet.espresso.network/v1/"
35+
max-transaction-size = 1048576

test-configs/c0/node_2.toml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ stamp = "/tmp/timeboost.2.stamp"
22

33
[net.public]
44
address = "127.0.0.1:8020"
5-
http_api = "127.0.0.1:8024"
5+
http-api = "127.0.0.1:8024"
66

77
[net.internal]
88
address = "127.0.0.1:8023"
@@ -24,11 +24,12 @@ namespace = 10101
2424

2525
[chain.parent]
2626
id = 31337
27-
rpc_url = "http://127.0.0.1:8545/"
28-
ibox_contract = "0xa0f3a1a4e2b2bcb7b48c8527c28098f207572ec1"
29-
block_tag = "finalized"
30-
key_manager_contract = "0x2bbf15bc655c4cc157b769cfcb1ea9924b9e1a35"
27+
rpc-url = "http://127.0.0.1:8545/"
28+
ibox-contract = "0xa0f3a1a4e2b2bcb7b48c8527c28098f207572ec1"
29+
block-tag = "finalized"
30+
key-manager-contract = "0x2bbf15bc655c4cc157b769cfcb1ea9924b9e1a35"
3131

3232
[espresso]
33-
base_url = "https://query.decaf.testnet.espresso.network/v1/"
34-
websockets_base_url = "wss://query.decaf.testnet.espresso.network/v1/"
33+
base-url = "https://query.decaf.testnet.espresso.network/v1/"
34+
websockets-base-url = "wss://query.decaf.testnet.espresso.network/v1/"
35+
max-transaction-size = 1048576

0 commit comments

Comments
 (0)