-
Notifications
You must be signed in to change notification settings - Fork 123
staticaddr: persist withdrawal info #938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
aab693b
to
e22b2b2
Compare
Rebased. |
Rebased |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but I think a quick sql store unit test would be nice
staticaddr/withdraw/sql_store.go
Outdated
|
||
// SqlStore is the backing store for static address withdrawals. | ||
type SqlStore struct { | ||
baseDB *loopdb.BaseDB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this exposes the full queries to this package, which IMO is not neccessary. as we usually define a Querier interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
|
||
-- deposit_outpoints is a concatenated list of outpoints that are used for | ||
-- this withdrawal. The list has the format txid1:idx;txid2:idx;... | ||
deposit_outpoints TEXT NOT NULL, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could it make sense to really sqlize this? and reference the db deposit id?
So add a table with:
ID, withdrawal_id REFRERNCES withdrawals.id(or tx_id), deposit_id REFERENCES(deposits.deposit_id)
I noticed we don't do the same in static loop ins, but it would allow for more interesting queries i feel.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I normalized the withdrawal and depoist tables by adding a new table withdrawal_deposits
and removed the deposit outpoints from the withdrawal record.
staticaddr/withdraw/sql_store.go
Outdated
} | ||
|
||
// CreateWithdrawal creates a static address withdrawal record in the database. | ||
func (s *SqlStore) CreateWithdrawal(ctx context.Context, tx *wire.MsgTx, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I propose adding a light unit test for future regressions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added sql_store_test.go
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice feature, added a couple of comments/suggestions.
|
||
-- deposit_outpoints is a concatenated list of outpoints that are used for | ||
-- this withdrawal. The list has the format txid1:idx;txid2:idx;... | ||
deposit_outpoints TEXT NOT NULL, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
|
||
-- confirmation_height is the block height at which the withdrawal was | ||
-- first confirmed. | ||
confirmation_height BIGINT NOT NULL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be allowed to be NULL
until the withdrawal confirms?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
staticaddr/withdraw/manager.go
Outdated
m.mu.Lock() | ||
delete(m.finalizedWithdrawalTxns, txHash) | ||
m.mu.Unlock() | ||
|
||
// Persist info about the finalized withdrawal. | ||
err = m.cfg.Store.CreateWithdrawal( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be nicer to add the withdrawal at the time it is requested then later on set it to confirmed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've reworked this so that we store a withdrawal at user request time with CreateWithdrawal
and then when its confirmed its updated with UpdateWithdrawal
.
staticaddr/withdraw/sql_store.go
Outdated
} | ||
|
||
// CreateWithdrawal creates a static address withdrawal record in the database. | ||
func (s *SqlStore) CreateWithdrawal(ctx context.Context, tx *wire.MsgTx, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
@hieblmi, remember to re-request review from reviewers when ready |
c835f14
to
ba77fff
Compare
469b6a2
to
8d95a80
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for the sql improvements and tests 💯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just one question!
staticaddr/withdraw/sql_store.go
Outdated
createArgs := sqlc.CreateWithdrawalParams{ | ||
WithdrawalID: id[:], | ||
TotalDepositAmount: int64(totalAmount), | ||
InitiationTime: time.Now(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: use the clock.
Also I noticed that there's mixed use of UTC vs non UTC timestamps in the staticaddr databases. I think we should always try to use UTC when possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🎉
addresses #936
sample output:
UPDATE: