Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Goshimmer_without_tipselection
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
COLLET Ismael
Goshimmer_without_tipselection
Commits
33b41497
Commit
33b41497
authored
5 years ago
by
Hans Moog
Browse files
Options
Downloads
Patches
Plain Diff
Feat: refactored delete logic
parent
292c4059
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
dapps/valuetransfers/packages/tangle/tangle.go
+58
-40
58 additions, 40 deletions
dapps/valuetransfers/packages/tangle/tangle.go
with
58 additions
and
40 deletions
dapps/valuetransfers/packages/tangle/tangle.go
+
58
−
40
View file @
33b41497
...
...
@@ -866,10 +866,6 @@ func (tangle *Tangle) deleteTransactionFutureCone(transactionID transaction.ID)
deleteStack
:=
list
.
New
()
deleteStack
.
PushBack
(
transactionID
)
// introduce map to keep track of queued transactions (so we don't process them twice)
queuedTransaction
:=
make
(
map
[
transaction
.
ID
]
types
.
Empty
)
queuedTransaction
[
transactionID
]
=
types
.
Void
// iterate through stack
for
deleteStack
.
Len
()
>=
1
{
// pop first element from stack
...
...
@@ -877,34 +873,59 @@ func (tangle *Tangle) deleteTransactionFutureCone(transactionID transaction.ID)
deleteStack
.
Remove
(
currentTransactionIDEntry
)
currentTransactionID
:=
currentTransactionIDEntry
.
Value
.
(
transaction
.
ID
)
// delete the transaction
consumers
,
attachments
:=
tangle
.
deleteTransaction
(
currentTransactionID
)
// queue consumers to also be deleted
for
_
,
consumer
:=
range
consumers
{
deleteStack
.
PushBack
(
consumer
)
}
// remove payload future cone
for
_
,
attachingPayloadID
:=
range
attachments
{
tangle
.
deletePayloadFutureCone
(
attachingPayloadID
)
}
}
}
// deleteTransaction deletes a single transaction and all of its related models from the database.
func
(
tangle
*
Tangle
)
deleteTransaction
(
transactionID
transaction
.
ID
)
(
consumers
[]
transaction
.
ID
,
attachments
[]
payload
.
ID
)
{
// create result
consumers
=
make
([]
transaction
.
ID
,
0
)
attachments
=
make
([]
payload
.
ID
,
0
)
// process transaction and its models
tangle
.
Transaction
(
currentT
ransactionID
)
.
Consume
(
func
(
tx
*
transaction
.
Transaction
)
{
tangle
.
Transaction
(
t
ransactionID
)
.
Consume
(
func
(
tx
*
transaction
.
Transaction
)
{
// mark transaction as deleted
tx
.
Delete
()
// cleanup inputs
tx
.
Inputs
()
.
ForEach
(
func
(
outputId
transaction
.
OutputID
)
bool
{
// delete consumer pointers of the inputs of the current transaction
tangle
.
consumerStorage
.
Delete
(
marshalutil
.
New
(
transaction
.
OutputIDLength
+
transaction
.
IDLength
)
.
WriteBytes
(
outputId
.
Bytes
())
.
WriteBytes
(
currentT
ransactionID
.
Bytes
())
.
Bytes
())
tangle
.
consumerStorage
.
Delete
(
marshalutil
.
New
(
transaction
.
OutputIDLength
+
transaction
.
IDLength
)
.
WriteBytes
(
outputId
.
Bytes
())
.
WriteBytes
(
t
ransactionID
.
Bytes
())
.
Bytes
())
return
true
})
// introduce map to keep track of seen consumers (so we don't process them twice)
seenConsumers
:=
make
(
map
[
transaction
.
ID
]
types
.
Empty
)
seenConsumers
[
transactionID
]
=
types
.
Void
// cleanup outputs
tx
.
Outputs
()
.
ForEach
(
func
(
addr
address
.
Address
,
balances
[]
*
balance
.
Balance
)
bool
{
// delete outputs
tangle
.
outputStorage
.
Delete
(
marshalutil
.
New
(
address
.
Length
+
transaction
.
IDLength
)
.
WriteBytes
(
addr
.
Bytes
())
.
WriteBytes
(
currentT
ransactionID
.
Bytes
())
.
Bytes
())
tangle
.
outputStorage
.
Delete
(
marshalutil
.
New
(
address
.
Length
+
transaction
.
IDLength
)
.
WriteBytes
(
addr
.
Bytes
())
.
WriteBytes
(
t
ransactionID
.
Bytes
())
.
Bytes
())
// process consumers
tangle
.
Consumers
(
transaction
.
NewOutputID
(
addr
,
currentT
ransactionID
))
.
Consume
(
func
(
consumer
*
Consumer
)
{
tangle
.
Consumers
(
transaction
.
NewOutputID
(
addr
,
t
ransactionID
))
.
Consume
(
func
(
consumer
*
Consumer
)
{
// check if the transaction has been queued already
if
_
,
transactionQueuedAlready
:=
queuedTransaction
[
consumer
.
TransactionID
()];
transactionQueued
Already
{
if
_
,
consumerSeenAlready
:=
seenConsumers
[
consumer
.
TransactionID
()];
consumerSeen
Already
{
return
}
queuedTransaction
[
consumer
.
TransactionID
()]
=
types
.
Void
seenConsumers
[
consumer
.
TransactionID
()]
=
types
.
Void
// queue consumers for deletion
deleteStack
.
PushBack
(
consumer
.
TransactionID
())
consumers
=
append
(
consumers
,
consumer
.
TransactionID
())
})
return
true
...
...
@@ -912,18 +933,15 @@ func (tangle *Tangle) deleteTransactionFutureCone(transactionID transaction.ID)
})
// delete transaction metadata
tangle
.
transactionMetadataStorage
.
Delete
(
currentT
ransactionID
.
Bytes
())
tangle
.
transactionMetadataStorage
.
Delete
(
t
ransactionID
.
Bytes
())
// process attachments
tangle
.
Attachments
(
currentTransactionID
)
.
Consume
(
func
(
attachment
*
Attachment
)
{
// remove payload future cone
tangle
.
deletePayloadFutureCone
(
attachment
.
PayloadID
())
})
}
}
tangle
.
Attachments
(
transactionID
)
.
Consume
(
func
(
attachment
*
Attachment
)
{
// remove attachment
attachment
.
Delete
()
func
(
tangle
*
Tangle
)
deleteTransaction
(
transactionID
transaction
.
ID
)
(
consumers
[]
transaction
.
ID
,
attachment
s
[]
p
ayload
.
ID
)
{
// TODO: IMPLEMENT METHOD
attachments
=
append
(
attachments
,
attachment
.
P
ayloadID
())
})
return
}
...
...
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