-
Notifications
You must be signed in to change notification settings - Fork 103
[sql-37] firewalldb: more preparations for SQL actions store #1070
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
Changes from all commits
297313e
8f7312f
b60dc29
3e963c0
f6e66db
9018cd4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import ( | |
"time" | ||
|
||
"github.com/lightninglabs/lightning-terminal/session" | ||
"github.com/lightningnetwork/lnd/fn" | ||
) | ||
|
||
// ActionState represents the state of an action. | ||
|
@@ -28,12 +29,21 @@ const ( | |
ActionStateError ActionState = 3 | ||
) | ||
|
||
// Action represents an RPC call made through the firewall. | ||
type Action struct { | ||
// SessionID is the ID of the session that this action belongs to. | ||
// Note that this is not serialized on persistence since the action is | ||
// already stored under a bucket identified by the session ID. | ||
SessionID session.ID | ||
// AddActionReq is the request that is used to add a new Action to the database. | ||
// It contains all the information that is needed to create a new Action in the | ||
// ActionStateInit State. | ||
type AddActionReq struct { | ||
// MacaroonIdentifier is a 4 byte identifier created from the last 4 | ||
// bytes of the root key ID of the macaroon used to perform the action. | ||
MacaroonIdentifier [4]byte | ||
|
||
// SessionID holds the optional session ID of the session that this | ||
// action was performed with. | ||
// | ||
// NOTE: for our BoltDB impl, this is not persisted in any way, and we | ||
// populate it by casting the macaroon ID to a session.ID and so is not | ||
// guaranteed to be linked to an existing session. | ||
SessionID fn.Option[session.ID] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if there's a test anywhere for an intercepted action, where we don't set this (i.e. it's not related to a session request). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah i'll expand on the tests for SQL (where it actually will matter if it is set or not) once we've added the sql impl here 👍 |
||
|
||
// ActorName is the name of the entity who performed the Action. | ||
ActorName string | ||
|
@@ -59,6 +69,11 @@ type Action struct { | |
|
||
// RPCParams is the method parameters of the request in JSON form. | ||
RPCParamsJson []byte | ||
} | ||
|
||
// Action represents an RPC call made through the firewall. | ||
type Action struct { | ||
AddActionReq | ||
|
||
// AttemptedAt is the time at which this action was created. | ||
AttemptedAt time.Time | ||
|
@@ -181,7 +196,7 @@ func WithActionState(state ActionState) ListActionOption { | |
// ActionsWriteDB is an abstraction over the Actions DB that will allow a | ||
// caller to add new actions as well as change the values of an existing action. | ||
type ActionsWriteDB interface { | ||
AddAction(ctx context.Context, action *Action) (ActionLocator, error) | ||
AddAction(ctx context.Context, req *AddActionReq) (ActionLocator, error) | ||
SetActionState(ctx context.Context, al ActionLocator, | ||
state ActionState, errReason string) error | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import ( | |
"time" | ||
|
||
"github.com/lightninglabs/lightning-terminal/session" | ||
"github.com/lightningnetwork/lnd/fn" | ||
"github.com/lightningnetwork/lnd/tlv" | ||
"go.etcd.io/bbolt" | ||
) | ||
|
@@ -53,8 +54,14 @@ var ( | |
) | ||
|
||
// AddAction serialises and adds an Action to the DB under the given sessionID. | ||
func (db *BoltDB) AddAction(_ context.Context, action *Action) (ActionLocator, | ||
error) { | ||
func (db *BoltDB) AddAction(_ context.Context, | ||
req *AddActionReq) (ActionLocator, error) { | ||
|
||
action := &Action{ | ||
AddActionReq: *req, | ||
AttemptedAt: db.clock.Now().UTC(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just noting that the time is set to the clocks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah - similarly to sessions/accounts - we're going with "it may just be off by a couple of hours and that's ok" since mostly these timestamps are just metadata for display to the user - we dont use them (much) in logic. So yeah - i think not worth a whole migration just to fix this |
||
State: ActionStateInit, | ||
} | ||
|
||
var buf bytes.Buffer | ||
if err := SerializeAction(&buf, action); err != nil { | ||
|
@@ -74,7 +81,7 @@ func (db *BoltDB) AddAction(_ context.Context, action *Action) (ActionLocator, | |
} | ||
|
||
sessBucket, err := actionsBucket.CreateBucketIfNotExists( | ||
action.SessionID[:], | ||
action.MacaroonIdentifier[:], | ||
) | ||
if err != nil { | ||
return err | ||
|
@@ -103,7 +110,7 @@ func (db *BoltDB) AddAction(_ context.Context, action *Action) (ActionLocator, | |
} | ||
|
||
locator = kvdbActionLocator{ | ||
sessionID: action.SessionID, | ||
sessionID: action.MacaroonIdentifier, | ||
actionID: nextActionIndex, | ||
} | ||
|
||
|
@@ -543,7 +550,8 @@ func DeserializeAction(r io.Reader, sessionID session.ID) (*Action, error) { | |
return nil, err | ||
} | ||
|
||
action.SessionID = sessionID | ||
action.MacaroonIdentifier = sessionID | ||
action.SessionID = fn.Some(sessionID) | ||
action.ActorName = string(actor) | ||
action.FeatureName = string(featureName) | ||
action.Trigger = string(trigger) | ||
|
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's probably not worth it to have another type alias for
[4]byte
?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.
currently we dont use this in other places - so i think it's ok for now