watchtower/wtdb: apply sanity checks to session policy before accepting
This commit is contained in:
parent
1979f9a7c0
commit
059887bd7b
@ -193,6 +193,12 @@ func (t *TowerDB) InsertSessionInfo(session *SessionInfo) error {
|
||||
return ErrSessionAlreadyExists
|
||||
}
|
||||
|
||||
// Perform a quick sanity check on the session policy before
|
||||
// accepting.
|
||||
if err := session.Policy.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = putSession(sessions, session)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -150,6 +150,13 @@ func testInsertSession(h *towerDBHarness) {
|
||||
RewardAddress: []byte{0x01, 0x02, 0x03},
|
||||
}
|
||||
|
||||
// Try to insert the session, which should fail since the policy doesn't
|
||||
// meet the current sanity checks.
|
||||
h.insertSession(session, wtpolicy.ErrSweepFeeRateTooLow)
|
||||
|
||||
// Now assign a sane sweep fee rate to the policy, inserting should
|
||||
// succeed.
|
||||
session.Policy.SweepFeeRate = wtpolicy.DefaultSweepFeeRate
|
||||
h.insertSession(session, nil)
|
||||
|
||||
session2 := h.getSession(&id, nil)
|
||||
|
@ -81,6 +81,11 @@ func (db *TowerDB) InsertSessionInfo(info *wtdb.SessionInfo) error {
|
||||
return wtdb.ErrSessionAlreadyExists
|
||||
}
|
||||
|
||||
// Perform a quick sanity check on the session policy before accepting.
|
||||
if err := info.Policy.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
db.sessions[info.ID] = info
|
||||
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue
Block a user