Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
duniter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
typescript
duniter
Commits
3040f42c
Commit
3040f42c
authored
4 years ago
by
Éloïs
Browse files
Options
Downloads
Patches
Plain Diff
[fix] gva:find_inputs: do not use inputs with amout less than 100
parent
6bf5eafa
No related branches found
No related tags found
1 merge request
!1346
Opti/gva txs history
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
rust-libs/modules/gva/dbs-reader/src/find_inputs.rs
+14
-12
14 additions, 12 deletions
rust-libs/modules/gva/dbs-reader/src/find_inputs.rs
rust-libs/modules/gva/dbs-reader/src/utxos.rs
+33
-29
33 additions, 29 deletions
rust-libs/modules/gva/dbs-reader/src/utxos.rs
with
47 additions
and
41 deletions
rust-libs/modules/gva/dbs-reader/src/find_inputs.rs
+
14
−
12
View file @
3040f42c
...
...
@@ -20,6 +20,8 @@ use crate::{
};
use
dubp
::{
documents
::
transaction
::
TransactionInputV10
,
wallet
::
prelude
::
*
};
pub
(
super
)
const
MIN_AMOUNT
:
i64
=
100
;
impl
DbsReader
{
pub
fn
find_inputs
<
BcDb
:
BcV2DbReadable
,
TxsMpDb
:
TxsMpV2DbReadable
>
(
&
self
,
...
...
@@ -59,9 +61,9 @@ impl DbsReader {
Ok
((
inputs
,
sum
))
})
?
.unwrap_or
((
Vec
::
with_capacity
(
50
),
SourceAmount
::
ZERO
))
.unwrap_or
((
Vec
::
with_capacity
(
50
0
),
SourceAmount
::
ZERO
))
}
else
{
(
Vec
::
with_capacity
(
50
),
SourceAmount
::
ZERO
)
(
Vec
::
with_capacity
(
50
0
),
SourceAmount
::
ZERO
)
};
// UDs
if
script
.nodes
.is_empty
()
{
...
...
@@ -142,7 +144,7 @@ mod tests {
WalletConditionsV2
,
};
const
UD0
:
i64
=
10
;
const
UD0
:
i64
=
10
0
;
#[test]
fn
test_find_inputs
()
->
anyhow
::
Result
<
()
>
{
...
...
@@ -160,7 +162,7 @@ mod tests {
let
script
=
WalletScriptV10
::
single
(
WalletConditionV10
::
Sig
(
pk
));
let
mut
pending_utxos
=
BTreeSet
::
new
();
pending_utxos
.insert
(
UtxoValV2
::
new
(
SourceAmount
::
with_base0
(
90
),
SourceAmount
::
with_base0
(
90
0
),
Hash
::
default
(),
10
,
));
...
...
@@ -177,11 +179,11 @@ mod tests {
.upsert
(
U32BE
(
0
),
b0
.median_time
)
?
;
gva_db
.gva_utxos_write
()
.upsert
(
GvaUtxoIdDbV1
::
new
(
script
.clone
(),
0
,
Hash
::
default
(),
0
),
SourceAmountValV2
(
SourceAmount
::
with_base0
(
50
)),
SourceAmountValV2
(
SourceAmount
::
with_base0
(
50
0
)),
)
?
;
gva_db
.gva_utxos_write
()
.upsert
(
GvaUtxoIdDbV1
::
new
(
script
.clone
(),
0
,
Hash
::
default
(),
1
),
SourceAmountValV2
(
SourceAmount
::
with_base0
(
80
)),
SourceAmountValV2
(
SourceAmount
::
with_base0
(
80
0
)),
)
?
;
txs_mp_db
.outputs_by_script_write
()
...
...
@@ -191,12 +193,12 @@ mod tests {
let
(
inputs
,
inputs_sum
)
=
db_reader
.find_inputs
(
&
bc_db
,
&
txs_mp_db
,
SourceAmount
::
with_base0
(
55
),
SourceAmount
::
with_base0
(
55
0
),
&
script
,
false
,
)
?
;
assert_eq!
(
inputs
.len
(),
2
);
assert_eq!
(
inputs_sum
,
SourceAmount
::
with_base0
(
60
));
assert_eq!
(
inputs_sum
,
SourceAmount
::
with_base0
(
60
0
));
// Insert tx1 inputs in mempool
txs_mp_db
...
...
@@ -210,12 +212,12 @@ mod tests {
let
(
inputs
,
inputs_sum
)
=
db_reader
.find_inputs
(
&
bc_db
,
&
txs_mp_db
,
SourceAmount
::
with_base0
(
55
),
SourceAmount
::
with_base0
(
55
0
),
&
script
,
false
,
)
?
;
assert_eq!
(
inputs
.len
(),
1
);
assert_eq!
(
inputs_sum
,
SourceAmount
::
with_base0
(
80
));
assert_eq!
(
inputs_sum
,
SourceAmount
::
with_base0
(
80
0
));
// Insert tx2 inputs in mempool
txs_mp_db
...
...
@@ -226,12 +228,12 @@ mod tests {
let
(
inputs
,
inputs_sum
)
=
db_reader
.find_inputs
(
&
bc_db
,
&
txs_mp_db
,
SourceAmount
::
with_base0
(
75
),
SourceAmount
::
with_base0
(
75
0
),
&
script
,
true
,
)
?
;
assert_eq!
(
inputs
.len
(),
1
);
assert_eq!
(
inputs_sum
,
SourceAmount
::
with_base0
(
90
));
assert_eq!
(
inputs_sum
,
SourceAmount
::
with_base0
(
90
0
));
Ok
(())
}
...
...
This diff is collapsed.
Click to expand it.
rust-libs/modules/gva/dbs-reader/src/utxos.rs
+
33
−
29
View file @
3040f42c
...
...
@@ -244,6 +244,9 @@ where
let
it
=
utxos_iter
.filter_map
(|
entry_res
|
match
entry_res
{
Ok
((
gva_utxo_id
,
SourceAmountValV2
(
utxo_amount
)))
=>
{
if
utxo_amount
.amount
()
<
super
::
find_inputs
::
MIN_AMOUNT
{
None
}
else
{
let
tx_hash
=
gva_utxo_id
.get_tx_hash
();
let
output_index
=
gva_utxo_id
.get_output_index
();
match
txs_mp_db_ro
...
...
@@ -262,6 +265,7 @@ where
Err
(
e
)
=>
Some
(
Err
(
e
)),
}
}
}
Err
(
e
)
=>
Some
(
Err
(
e
)),
});
let
utxos
=
if
let
Some
(
limit
)
=
page_info
.limit_opt
{
...
...
@@ -320,15 +324,15 @@ mod tests {
gva_db
.gva_utxos_write
()
.upsert
(
GvaUtxoIdDbV1
::
new
(
script
.clone
(),
0
,
Hash
::
default
(),
0
),
SourceAmountValV2
(
SourceAmount
::
with_base0
(
50
)),
SourceAmountValV2
(
SourceAmount
::
with_base0
(
50
0
)),
)
?
;
gva_db
.gva_utxos_write
()
.upsert
(
GvaUtxoIdDbV1
::
new
(
script
.clone
(),
0
,
Hash
::
default
(),
1
),
SourceAmountValV2
(
SourceAmount
::
with_base0
(
80
)),
SourceAmountValV2
(
SourceAmount
::
with_base0
(
80
0
)),
)
?
;
gva_db
.gva_utxos_write
()
.upsert
(
GvaUtxoIdDbV1
::
new
(
script
.clone
(),
0
,
Hash
::
default
(),
2
),
SourceAmountValV2
(
SourceAmount
::
with_base0
(
120
)),
SourceAmountValV2
(
SourceAmount
::
with_base0
(
120
0
)),
)
?
;
// Find utxos with amount target
...
...
@@ -338,7 +342,7 @@ mod tests {
has_previous_page
,
}
=
db_reader
.find_script_utxos
(
&
txs_mp_db
,
Some
(
SourceAmount
::
with_base0
(
55
)),
Some
(
SourceAmount
::
with_base0
(
55
0
)),
PageInfo
::
default
(),
&
script
,
)
?
;
...
...
@@ -352,7 +356,7 @@ mod tests {
tx_hash
:
Hash
::
default
(),
output_index
:
0
,
},
SourceAmount
::
with_base0
(
50
)
SourceAmount
::
with_base0
(
50
0
)
),
(
UtxoCursor
{
...
...
@@ -360,11 +364,11 @@ mod tests {
tx_hash
:
Hash
::
default
(),
output_index
:
1
,
},
SourceAmount
::
with_base0
(
80
)
SourceAmount
::
with_base0
(
80
0
)
),
]
);
assert_eq!
(
sum
,
SourceAmount
::
with_base0
(
130
));
assert_eq!
(
sum
,
SourceAmount
::
with_base0
(
130
0
));
assert!
(
!
has_next_page
);
assert!
(
!
has_previous_page
);
...
...
@@ -374,7 +378,7 @@ mod tests {
..
}
=
db_reader
.find_script_utxos
(
&
txs_mp_db
,
Some
(
SourceAmount
::
with_base0
(
55
)),
Some
(
SourceAmount
::
with_base0
(
55
0
)),
PageInfo
{
order
:
false
,
..
Default
::
default
()
...
...
@@ -390,10 +394,10 @@ mod tests {
tx_hash
:
Hash
::
default
(),
output_index
:
2
,
},
SourceAmount
::
with_base0
(
120
)
SourceAmount
::
with_base0
(
120
0
)
),]
);
assert_eq!
(
sum
,
SourceAmount
::
with_base0
(
120
));
assert_eq!
(
sum
,
SourceAmount
::
with_base0
(
120
0
));
assert!
(
!
has_next_page
);
assert!
(
!
has_previous_page
);
...
...
@@ -422,7 +426,7 @@ mod tests {
tx_hash
:
Hash
::
default
(),
output_index
:
2
,
},
SourceAmount
::
with_base0
(
120
)
SourceAmount
::
with_base0
(
120
0
)
),
(
UtxoCursor
{
...
...
@@ -430,11 +434,11 @@ mod tests {
tx_hash
:
Hash
::
default
(),
output_index
:
1
,
},
SourceAmount
::
with_base0
(
80
)
SourceAmount
::
with_base0
(
80
0
)
)
]
);
assert_eq!
(
sum
,
SourceAmount
::
with_base0
(
200
));
assert_eq!
(
sum
,
SourceAmount
::
with_base0
(
200
0
));
assert!
(
!
has_next_page
);
assert!
(
has_previous_page
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment