Skip to content

Commit 6f2edce

Browse files
committed
Accept inputs for pool and delegation ids
1 parent 9732d80 commit 6f2edce

File tree

36 files changed

+365
-346
lines changed

36 files changed

+365
-346
lines changed

api-server/scanner-lib/src/blockchain_state/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,11 +1627,10 @@ async fn update_tables_from_transaction_outputs<T: ApiServerStorageWrite>(
16271627
}
16281628
TxOutput::ProduceBlockFromStake(_, _) => {}
16291629
TxOutput::CreateDelegationId(destination, pool_id) => {
1630-
if let Some(input0_outpoint) = inputs.iter().find_map(|input| input.utxo_outpoint())
1631-
{
1630+
if let Some(delegation_id) = make_delegation_id(inputs) {
16321631
db_tx
16331632
.set_delegation_at_height(
1634-
make_delegation_id(input0_outpoint),
1633+
delegation_id,
16351634
&Delegation::new(
16361635
block_height,
16371636
destination.clone(),

api-server/scanner-lib/src/blockchain_state/pos_adapter.rs

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

1616
use api_server_common::storage::storage_api::Delegation;
17-
use common::chain::{DelegationId, Destination, PoolId, UtxoOutPoint};
17+
use common::chain::{DelegationId, Destination, PoolId};
1818
use common::primitives::Amount;
1919
use pos_accounting::{
2020
DelegationData, FlushablePoSAccountingView, InMemoryPoSAccounting, PoSAccountingDB,
@@ -164,9 +164,9 @@ impl PoSAccountingOperations<()> for PoSAdapter {
164164
fn create_delegation_id(
165165
&mut self,
166166
_target_pool: PoolId,
167+
_delegation_id: DelegationId,
167168
_spend_key: Destination,
168-
_input0_outpoint: &UtxoOutPoint,
169-
) -> Result<(DelegationId, ()), pos_accounting::Error> {
169+
) -> Result<(), pos_accounting::Error> {
170170
unimplemented!()
171171
}
172172

api-server/scanner-lib/src/sync/tests/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ use chainstate_test_framework::{TestFramework, TransactionBuilder};
4040
use common::{
4141
address::Address,
4242
chain::{
43-
make_delegation_id, make_pool_id,
4443
output_value::OutputValue,
4544
signature::{
4645
inputsig::{
@@ -51,8 +50,8 @@ use common::{
5150
},
5251
stakelock::StakePoolData,
5352
timelock::OutputTimeLock,
54-
CoinUnit, Destination, OutPointSourceId, PoolId, SignedTransaction, TxInput, TxOutput,
55-
UtxoOutPoint,
53+
CoinUnit, DelegationId, Destination, OutPointSourceId, PoolId, SignedTransaction, TxInput,
54+
TxOutput, UtxoOutPoint,
5655
},
5756
primitives::{per_thousand::PerThousand, Amount, CoinOrTokenId, Idable, H256},
5857
};
@@ -423,7 +422,7 @@ async fn compare_pool_rewards_with_chainstate_real_state(#[case] seed: Seed) {
423422
pool_id,
424423
))
425424
.build();
426-
let delegation_id = make_delegation_id(&UtxoOutPoint::new(
425+
let delegation_id = DelegationId::from_utxo(&UtxoOutPoint::new(
427426
OutPointSourceId::Transaction(prev_tx_id),
428427
0,
429428
));
@@ -507,7 +506,7 @@ async fn compare_pool_rewards_with_chainstate_real_state(#[case] seed: Seed) {
507506
PerThousand::new_from_rng(&mut rng),
508507
Amount::from_atoms(rng.gen_range(0..100)),
509508
);
510-
let new_pool_id = make_pool_id(&UtxoOutPoint::new(
509+
let new_pool_id = PoolId::from_utxo(&UtxoOutPoint::new(
511510
OutPointSourceId::Transaction(prev_tx_id),
512511
0,
513512
));

api-server/scanner-lib/src/sync/tests/simulation.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,6 @@ async fn simulation(
373373
utxo_outpoints.extend(new_utxos);
374374

375375
// store new ids
376-
let input0_outpoint = tx.inputs().iter().find_map(|input| input.utxo_outpoint());
377376
tx.outputs().iter().for_each(|out| match out {
378377
TxOutput::CreateStakePool(pool_id, _) => {
379378
staking_pools.insert(*pool_id);
@@ -384,7 +383,7 @@ async fn simulation(
384383
);
385384
}
386385
TxOutput::CreateDelegationId(_, _) => {
387-
delegations.insert(make_delegation_id(input0_outpoint.unwrap()));
386+
delegations.insert(make_delegation_id(tx.inputs()).unwrap());
388387
}
389388
| TxOutput::Burn(_)
390389
| TxOutput::Transfer(_, _)

api-server/stack-test-suite/tests/v2/helpers.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use chainstate_test_framework::{TestFramework, TransactionBuilder};
1818
use common::{
1919
address::pubkeyhash::PublicKeyHash,
2020
chain::{
21-
make_delegation_id, make_pool_id, make_token_id,
21+
make_token_id,
2222
output_value::OutputValue,
2323
stakelock::StakePoolData,
2424
tokens::{TokenId, TokenIssuance, TokenTotalSupply},
@@ -56,7 +56,7 @@ pub fn prepare_stake_pool(
5656
PerThousand::new(margin_ratio_per_thousand).unwrap(),
5757
Amount::ZERO,
5858
);
59-
let pool_id = make_pool_id(&stake_pool_outpoint);
59+
let pool_id = PoolId::from_utxo(&stake_pool_outpoint);
6060

6161
*available_amount = (*available_amount - amount_to_stake).unwrap();
6262
let stake_pool_transaction = TransactionBuilder::new()
@@ -90,7 +90,7 @@ pub fn prepare_delegation(
9090
destination: Option<Destination>,
9191
tf: &mut TestFramework,
9292
) -> (DelegationId, Destination, UtxoOutPoint, Block) {
93-
let delegation_id = make_delegation_id(&transfer_outpoint);
93+
let delegation_id = DelegationId::from_utxo(&transfer_outpoint);
9494
let (_, pk) = PrivateKey::new_from_rng(rng, KeyKind::Secp256k1Schnorr);
9595
let destination = destination.unwrap_or(Destination::PublicKey(pk));
9696
let create_delegation_tx = TransactionBuilder::new()

blockprod/src/detail/timestamp_searcher/tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ mod collect_search_data {
3434
use common::{
3535
chain::{
3636
self, config::ChainType, output_value::OutputValue, CoinUnit, ConsensusUpgrade,
37-
Destination, NetUpgrades, OutPointSourceId, PoSChainConfigBuilder, PoSConsensusVersion,
38-
PoolId, TxOutput, UtxoOutPoint,
37+
DelegationId, Destination, NetUpgrades, OutPointSourceId, PoSChainConfigBuilder,
38+
PoSConsensusVersion, PoolId, TxOutput, UtxoOutPoint,
3939
},
4040
primitives::{Amount, BlockCount, BlockHeight, Idable, H256},
4141
};
@@ -428,7 +428,7 @@ mod collect_search_data {
428428
Amount::from_atoms(rng.gen_range(min_stake_pool_pledge..(min_stake_pool_pledge * 10)));
429429

430430
let (pool_data, _) = create_stake_pool_data_with_all_reward_to_staker(rng, pledge, vrf_pk);
431-
let pool_id = common::chain::make_pool_id(utxo_for_spending.outpoint());
431+
let pool_id = PoolId::from_utxo(utxo_for_spending.outpoint());
432432

433433
let tx_builder = TransactionBuilder::new()
434434
.add_output(TxOutput::CreateStakePool(pool_id, Box::new(pool_data)));
@@ -450,7 +450,7 @@ mod collect_search_data {
450450
let amount_to_delegate =
451451
Amount::from_atoms(rng.gen_range(min_stake_pool_pledge / 2..min_stake_pool_pledge * 2));
452452

453-
let delegation_id = common::chain::make_delegation_id(utxo_for_spending.outpoint());
453+
let delegation_id = DelegationId::from_utxo(utxo_for_spending.outpoint());
454454
let tx1_builder = TransactionBuilder::new()
455455
.add_output(TxOutput::CreateDelegationId(
456456
Destination::AnyoneCanSpend,

chainstate/test-framework/src/random_tx_maker.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use chainstate::chainstate_interface::ChainstateInterface;
2525
use common::{
2626
chain::{
2727
htlc::{HashedTimelockContract, HtlcSecretHash},
28-
make_order_id, make_pool_id, make_token_id,
28+
make_delegation_id, make_order_id, make_pool_id, make_token_id,
2929
output_value::OutputValue,
3030
stakelock::StakePoolData,
3131
timelock::OutputTimeLock,
@@ -1384,7 +1384,7 @@ impl<'a> RandomTxMaker<'a> {
13841384
| TxOutput::DataDeposit(_)
13851385
| TxOutput::Htlc(_, _) => Some(output),
13861386
TxOutput::CreateStakePool(dummy_pool_id, pool_data) => {
1387-
let pool_id = make_pool_id(inputs[0].utxo_outpoint().unwrap());
1387+
let pool_id = make_pool_id(inputs).unwrap();
13881388
let (vrf_sk, vrf_pk) = VRFPrivateKey::new_from_rng(rng, VRFKeyKind::Schnorrkel);
13891389
let (staker_sk, staker_pk) =
13901390
PrivateKey::new_from_rng(rng, KeyKind::Secp256k1Schnorr);
@@ -1408,12 +1408,9 @@ impl<'a> RandomTxMaker<'a> {
14081408
}
14091409
TxOutput::CreateDelegationId(destination, pool_id) => {
14101410
if pos_accounting_cache.pool_exists(*pool_id).unwrap() {
1411+
let delegation_id = make_delegation_id(inputs).unwrap();
14111412
let _ = pos_accounting_cache
1412-
.create_delegation_id(
1413-
*pool_id,
1414-
destination.clone(),
1415-
inputs[0].utxo_outpoint().unwrap(),
1416-
)
1413+
.create_delegation_id(*pool_id, delegation_id, destination.clone())
14171414
.unwrap();
14181415
Some(output)
14191416
} else {

chainstate/test-suite/src/tests/chainstate_accounting_storage_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ fn make_tx_with_stake_pool(
7878
amount_to_transfer: Amount,
7979
) -> (SignedTransaction, PoolId, PoolData, UtxoOutPoint) {
8080
let destination = new_pub_key_destination(rng);
81-
let pool_id = common::chain::make_pool_id(&input0_outpoint);
81+
let pool_id = PoolId::from_utxo(&input0_outpoint);
8282
let pool_data = create_pool_data(rng, destination, amount_to_stake);
8383
let stake_output = TxOutput::CreateStakePool(
8484
pool_id,

chainstate/test-suite/src/tests/delegation_tests.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn prepare_stake_pool(
6161
OutPointSourceId::BlockReward(tf.genesis().get_id().into()),
6262
0,
6363
);
64-
let pool_id = common::chain::make_pool_id(&genesis_outpoint);
64+
let pool_id = PoolId::from_utxo(&genesis_outpoint);
6565

6666
let tx = TransactionBuilder::new()
6767
.add_input(genesis_outpoint.into(), empty_witness(rng))
@@ -101,7 +101,7 @@ fn prepare_delegation(
101101

102102
let available_amount = get_coin_amount_from_outpoint(&tf.storage, &transfer_outpoint);
103103

104-
let delegation_id = common::chain::make_delegation_id(&transfer_outpoint);
104+
let delegation_id = DelegationId::from_utxo(&transfer_outpoint);
105105
let tx = TransactionBuilder::new()
106106
.add_input(transfer_outpoint.into(), empty_witness(rng))
107107
.add_output(TxOutput::CreateDelegationId(
@@ -150,7 +150,7 @@ fn create_delegation(#[case] seed: Seed) {
150150
let mut tf = TestFramework::builder(&mut rng).build();
151151

152152
let (pool_id, _, transfer_outpoint) = prepare_stake_pool(&mut rng, &mut tf);
153-
let delegation_id = common::chain::make_delegation_id(&transfer_outpoint);
153+
let delegation_id = DelegationId::from_utxo(&transfer_outpoint);
154154
let available_amount = get_coin_amount_from_outpoint(&tf.storage, &transfer_outpoint);
155155

156156
let delegation_spend_destination =
@@ -244,7 +244,7 @@ fn create_delegation_twice(#[case] seed: Seed) {
244244
OutPointSourceId::BlockReward(tf.genesis().get_id().into()),
245245
0,
246246
);
247-
let pool_id = common::chain::make_pool_id(&genesis_outpoint);
247+
let pool_id = PoolId::from_utxo(&genesis_outpoint);
248248

249249
// create pool and 2 transfer utxos
250250
let tx = TransactionBuilder::new()
@@ -797,7 +797,7 @@ fn create_pool_and_delegation_and_delegate_same_block(#[case] seed: Seed) {
797797
OutPointSourceId::BlockReward(tf.genesis().get_id().into()),
798798
0,
799799
);
800-
let pool_id = common::chain::make_pool_id(&genesis_outpoint);
800+
let pool_id = PoolId::from_utxo(&genesis_outpoint);
801801

802802
let tx1 = TransactionBuilder::new()
803803
.add_input(genesis_outpoint.into(), empty_witness(&mut rng))
@@ -813,7 +813,7 @@ fn create_pool_and_delegation_and_delegate_same_block(#[case] seed: Seed) {
813813
let tx1_source_id = OutPointSourceId::Transaction(tx1.transaction().get_id());
814814
let tx_1_kernel0_outpoint = UtxoOutPoint::new(tx1_source_id, 1);
815815

816-
let delegation_id = common::chain::make_delegation_id(&tx_1_kernel0_outpoint);
816+
let delegation_id = DelegationId::from_utxo(&tx_1_kernel0_outpoint);
817817
let tx2 = TransactionBuilder::new()
818818
.add_input(tx_1_kernel0_outpoint.into(), empty_witness(&mut rng))
819819
.add_output(TxOutput::CreateDelegationId(
@@ -857,7 +857,7 @@ fn check_signature_on_spend_share(#[case] seed: Seed) {
857857
let mut tf = TestFramework::builder(&mut rng).build();
858858

859859
let (pool_id, _, transfer_outpoint) = prepare_stake_pool(&mut rng, &mut tf);
860-
let delegation_id = common::chain::make_delegation_id(&transfer_outpoint);
860+
let delegation_id = DelegationId::from_utxo(&transfer_outpoint);
861861
let available_amount = get_coin_amount_from_outpoint(&tf.storage, &transfer_outpoint);
862862

863863
let (delegation_sk, delegation_pk) =
@@ -1441,7 +1441,7 @@ fn delegate_and_spend_share_same_block_multiple_delegations(#[case] seed: Seed)
14411441
let change = (available_amount - amount_to_delegate).unwrap();
14421442

14431443
// Create second delegation and delegate coins to both
1444-
let delegation_id_2 = common::chain::make_delegation_id(&transfer_outpoint);
1444+
let delegation_id_2 = DelegationId::from_utxo(&transfer_outpoint);
14451445
let delegate_staking_tx = TransactionBuilder::new()
14461446
.add_input(transfer_outpoint.clone().into(), empty_witness(&mut rng))
14471447
.add_output(TxOutput::DelegateStaking(
@@ -1730,7 +1730,7 @@ fn delegate_same_pool_as_staking(#[case] seed: Seed) {
17301730
))
17311731
.build();
17321732
let create_delegation_tx_id = create_delegation_tx.transaction().get_id();
1733-
let delegation_id = common::chain::make_delegation_id(&genesis_mint_outpoint);
1733+
let delegation_id = DelegationId::from_utxo(&genesis_mint_outpoint);
17341734

17351735
let delegate_staking_tx = TransactionBuilder::new()
17361736
.add_input(

chainstate/test-suite/src/tests/get_stake_pool_balances_at_heights.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ impl TestData {
409409
Amount::from_atoms(rng.gen_range(min_stake_pool_pledge..(min_stake_pool_pledge * 10)));
410410
let (stake_pool_data, staker_key) =
411411
create_stake_pool_data_with_all_reward_to_staker(rng, pledge, vrf_pk);
412-
let pool_id = common::chain::make_pool_id(self.utxo_for_spending.outpoint());
412+
let pool_id = PoolId::from_utxo(self.utxo_for_spending.outpoint());
413413

414414
let tx_builder = TransactionBuilder::new().add_output(TxOutput::CreateStakePool(
415415
pool_id,
@@ -500,7 +500,7 @@ impl TestData {
500500
let amount_to_delegate =
501501
Amount::from_atoms(rng.gen_range(min_stake_pool_pledge / 2..min_stake_pool_pledge * 2));
502502

503-
let delegation_id = common::chain::make_delegation_id(self.utxo_for_spending.outpoint());
503+
let delegation_id = DelegationId::from_utxo(self.utxo_for_spending.outpoint());
504504
let tx1_builder = TransactionBuilder::new()
505505
.add_output(TxOutput::CreateDelegationId(
506506
Destination::AnyoneCanSpend,

chainstate/test-suite/src/tests/homomorphism.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ use common::{
2424
output_value::OutputValue,
2525
timelock::OutputTimeLock,
2626
tokens::{TokenId, TokenIssuance},
27-
AccountCommand, AccountNonce, Destination, OutPointSourceId, TxInput, TxOutput,
28-
UtxoOutPoint,
27+
AccountCommand, AccountNonce, DelegationId, Destination, OutPointSourceId, PoolId, TxInput,
28+
TxOutput, UtxoOutPoint,
2929
},
3030
primitives::{Amount, Idable},
3131
};
@@ -289,7 +289,7 @@ fn pos_accounting_homomorphism(#[case] seed: Seed) {
289289
vrf_pk,
290290
);
291291
let genesis_outpoint = UtxoOutPoint::new(OutPointSourceId::BlockReward(genesis_id), 0);
292-
let pool_id = common::chain::make_pool_id(&genesis_outpoint);
292+
let pool_id = PoolId::from_utxo(&genesis_outpoint);
293293

294294
let storage2 = TestStore::new_empty().unwrap();
295295
let mut tf2 = TestFramework::builder(&mut rng)
@@ -328,10 +328,8 @@ fn pos_accounting_homomorphism(#[case] seed: Seed) {
328328
))
329329
.build();
330330

331-
let delegation_id = common::chain::make_delegation_id(&UtxoOutPoint::new(
332-
tx_1.transaction().get_id().into(),
333-
1,
334-
));
331+
let delegation_id =
332+
DelegationId::from_utxo(&UtxoOutPoint::new(tx_1.transaction().get_id().into(), 1));
335333
let tx_3 = TransactionBuilder::new()
336334
.add_input(
337335
TxInput::from_utxo(

0 commit comments

Comments
 (0)