mirror of
https://github.com/lightninglabs/lightning-terminal.git
synced 2026-08-13 12:33:36 +02:00
firewalldb: thread context to PseudoToReal
Update the PseudoToReal method of the PrivacyMapTx interface to take a context.
This commit is contained in:
parent
197ee3b5ba
commit
7e8e4a9920
7 changed files with 40 additions and 28 deletions
|
|
@ -559,7 +559,7 @@ func handleListChannelsRequest(db firewalldb.PrivacyMapDB,
|
|||
err := db.View(ctx, func(ctx context.Context,
|
||||
tx firewalldb.PrivacyMapTx) error {
|
||||
|
||||
peer, err := firewalldb.RevealBytes(tx, r.Peer)
|
||||
peer, err := firewalldb.RevealBytes(ctx, tx, r.Peer)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -778,8 +778,8 @@ func handleUpdatePolicyRequest(db firewalldb.PrivacyMapDB,
|
|||
tx firewalldb.PrivacyMapTx) error {
|
||||
|
||||
var err error
|
||||
newTxid, newIndex, err = firewalldb.RevealChanPoint(
|
||||
tx, newTxid, newIndex,
|
||||
newTxid, newIndex, err = firewalldb.RevealChanPoint( //nolint:lll
|
||||
ctx, tx, newTxid, newIndex,
|
||||
)
|
||||
return err
|
||||
})
|
||||
|
|
@ -1380,7 +1380,7 @@ func handleBatchOpenChannelRequest(db firewalldb.PrivacyMapDB,
|
|||
nodePubkey := c.NodePubkey
|
||||
if !flags.Contains(session.ClearPubkeys) {
|
||||
nodePubkey, err = firewalldb.RevealBytes(
|
||||
tx, c.NodePubkey,
|
||||
ctx, tx, c.NodePubkey,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -1518,7 +1518,7 @@ func handleChannelOpenRequest(db firewalldb.PrivacyMapDB,
|
|||
|
||||
if !flags.Contains(session.ClearPubkeys) {
|
||||
nodePubkey, err = firewalldb.RevealBytes(
|
||||
tx, nodePubkey,
|
||||
ctx, tx, nodePubkey,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -1665,7 +1665,7 @@ func handleConnectPeerRequest(db firewalldb.PrivacyMapDB,
|
|||
pubkey := r.Addr.Pubkey
|
||||
if !flags.Contains(session.ClearPubkeys) {
|
||||
pubkey, err = firewalldb.RevealString(
|
||||
tx, r.Addr.Pubkey,
|
||||
ctx, tx, r.Addr.Pubkey,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -1675,7 +1675,7 @@ func handleConnectPeerRequest(db firewalldb.PrivacyMapDB,
|
|||
host := r.Addr.Host
|
||||
if !flags.Contains(session.ClearNetworkAddresses) {
|
||||
host, err = firewalldb.RevealString(
|
||||
tx, r.Addr.Host,
|
||||
ctx, tx, r.Addr.Host,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -1129,7 +1129,9 @@ func (m *mockPrivacyMapDB) NewPair(_ context.Context, real,
|
|||
return nil
|
||||
}
|
||||
|
||||
func (m *mockPrivacyMapDB) PseudoToReal(pseudo string) (string, error) {
|
||||
func (m *mockPrivacyMapDB) PseudoToReal(_ context.Context, pseudo string) (
|
||||
string, error) {
|
||||
|
||||
r, ok := m.p2r[pseudo]
|
||||
if !ok {
|
||||
return "", firewalldb.ErrNoSuchKeyFound
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ type PrivacyMapTx interface {
|
|||
|
||||
// PseudoToReal returns the real value associated with the given pseudo
|
||||
// value. If no such pair is found, then ErrNoSuchKeyFound is returned.
|
||||
PseudoToReal(pseudo string) (string, error)
|
||||
PseudoToReal(ctx context.Context, pseudo string) (string, error)
|
||||
|
||||
// RealToPseudo returns the pseudo value associated with the given real
|
||||
// value. If no such pair is found, then ErrNoSuchKeyFound is returned.
|
||||
|
|
@ -228,7 +228,9 @@ func (p *privacyMapTx) NewPair(_ context.Context, real, pseudo string) error {
|
|||
// it does then the real value is returned, else an error is returned.
|
||||
//
|
||||
// NOTE: this is part of the PrivacyMapTx interface.
|
||||
func (p *privacyMapTx) PseudoToReal(pseudo string) (string, error) {
|
||||
func (p *privacyMapTx) PseudoToReal(_ context.Context, pseudo string) (string,
|
||||
error) {
|
||||
|
||||
privacyBucket, err := getBucket(p.boltTx, privacyBucketKey)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
|
@ -354,12 +356,14 @@ func NewPseudoStr(n int) (string, error) {
|
|||
return string(b), nil
|
||||
}
|
||||
|
||||
func RevealString(tx PrivacyMapTx, pseudo string) (string, error) {
|
||||
func RevealString(ctx context.Context, tx PrivacyMapTx, pseudo string) (string,
|
||||
error) {
|
||||
|
||||
if pseudo == "" {
|
||||
return pseudo, nil
|
||||
}
|
||||
|
||||
return tx.PseudoToReal(pseudo)
|
||||
return tx.PseudoToReal(ctx, pseudo)
|
||||
}
|
||||
|
||||
func HideUint64(ctx context.Context, tx PrivacyMapTx, real uint64) (uint64,
|
||||
|
|
@ -382,12 +386,14 @@ func HideUint64(ctx context.Context, tx PrivacyMapTx, real uint64) (uint64,
|
|||
return pseudoUint64, nil
|
||||
}
|
||||
|
||||
func RevealUint64(tx PrivacyMapTx, pseudo uint64) (uint64, error) {
|
||||
func RevealUint64(ctx context.Context, tx PrivacyMapTx, pseudo uint64) (uint64,
|
||||
error) {
|
||||
|
||||
if pseudo == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
real, err := tx.PseudoToReal(Uint64ToStr(pseudo))
|
||||
real, err := tx.PseudoToReal(ctx, Uint64ToStr(pseudo))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
|
@ -429,11 +435,11 @@ func NewPseudoChanPoint() (string, error) {
|
|||
return fmt.Sprintf("%s:%d", pseudoTXID, pseudoIndex), nil
|
||||
}
|
||||
|
||||
func RevealChanPoint(tx PrivacyMapTx, txid string, index uint32) (string,
|
||||
uint32, error) {
|
||||
func RevealChanPoint(ctx context.Context, tx PrivacyMapTx, txid string,
|
||||
index uint32) (string, uint32, error) {
|
||||
|
||||
fakePoint := fmt.Sprintf("%s:%d", txid, index)
|
||||
real, err := tx.PseudoToReal(fakePoint)
|
||||
real, err := tx.PseudoToReal(ctx, fakePoint)
|
||||
if err != nil {
|
||||
return "", 0, err
|
||||
}
|
||||
|
|
@ -477,13 +483,15 @@ func HideBytes(ctx context.Context, tx PrivacyMapTx, realBytes []byte) ([]byte,
|
|||
return hex.DecodeString(pseudo)
|
||||
}
|
||||
|
||||
func RevealBytes(tx PrivacyMapTx, pseudoBytes []byte) ([]byte, error) {
|
||||
func RevealBytes(ctx context.Context, tx PrivacyMapTx,
|
||||
pseudoBytes []byte) ([]byte, error) {
|
||||
|
||||
if pseudoBytes == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
pseudo := hex.EncodeToString(pseudoBytes)
|
||||
pseudo, err := RevealString(tx, pseudo)
|
||||
pseudo, err := RevealString(ctx, tx, pseudo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ func TestPrivacyMapStorage(t *testing.T) {
|
|||
_, err = tx.RealToPseudo("real")
|
||||
require.ErrorIs(t, err, ErrNoSuchKeyFound)
|
||||
|
||||
_, err = tx.PseudoToReal("pseudo")
|
||||
_, err = tx.PseudoToReal(ctx, "pseudo")
|
||||
require.ErrorIs(t, err, ErrNoSuchKeyFound)
|
||||
|
||||
err = tx.NewPair(ctx, "real", "pseudo")
|
||||
|
|
@ -36,7 +36,7 @@ func TestPrivacyMapStorage(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
require.Equal(t, "pseudo", pseudo)
|
||||
|
||||
real, err := tx.PseudoToReal("pseudo")
|
||||
real, err := tx.PseudoToReal(ctx, "pseudo")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "real", real)
|
||||
|
||||
|
|
@ -56,7 +56,7 @@ func TestPrivacyMapStorage(t *testing.T) {
|
|||
_, err = tx.RealToPseudo("real")
|
||||
require.ErrorIs(t, err, ErrNoSuchKeyFound)
|
||||
|
||||
_, err = tx.PseudoToReal("pseudo")
|
||||
_, err = tx.PseudoToReal(ctx, "pseudo")
|
||||
require.ErrorIs(t, err, ErrNoSuchKeyFound)
|
||||
|
||||
err = tx.NewPair(ctx, "real 2", "pseudo 2")
|
||||
|
|
@ -66,7 +66,7 @@ func TestPrivacyMapStorage(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
require.Equal(t, "pseudo 2", pseudo)
|
||||
|
||||
real, err := tx.PseudoToReal("pseudo 2")
|
||||
real, err := tx.PseudoToReal(ctx, "pseudo 2")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "real 2", real)
|
||||
|
||||
|
|
|
|||
|
|
@ -353,7 +353,7 @@ func (c *ChannelRestrict) PseudoToReal(ctx context.Context,
|
|||
tx firewalldb.PrivacyMapTx) error {
|
||||
|
||||
for i, chanID := range c.DenyList {
|
||||
real, err := firewalldb.RevealUint64(tx, chanID)
|
||||
real, err := firewalldb.RevealUint64(ctx, tx, chanID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -394,11 +394,13 @@ func (c *PeerRestrict) PseudoToReal(ctx context.Context,
|
|||
return &PeerRestrict{DenyList: restrictList}, nil
|
||||
}
|
||||
|
||||
err := db.View(ctx, func(_ context.Context,
|
||||
err := db.View(ctx, func(ctx context.Context,
|
||||
tx firewalldb.PrivacyMapTx) error {
|
||||
|
||||
for i, peerPubKey := range c.DenyList {
|
||||
real, err := firewalldb.RevealString(tx, peerPubKey)
|
||||
real, err := firewalldb.RevealString(
|
||||
ctx, tx, peerPubKey,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -629,7 +629,7 @@ func (s *sessionRpcServer) PrivacyMapConversion(ctx context.Context,
|
|||
|
||||
var res string
|
||||
privMap := s.cfg.privMap(groupID)
|
||||
err = privMap.View(ctx, func(_ context.Context,
|
||||
err = privMap.View(ctx, func(ctx context.Context,
|
||||
tx firewalldb.PrivacyMapTx) error {
|
||||
|
||||
var err error
|
||||
|
|
@ -638,7 +638,7 @@ func (s *sessionRpcServer) PrivacyMapConversion(ctx context.Context,
|
|||
return err
|
||||
}
|
||||
|
||||
res, err = tx.PseudoToReal(req.Input)
|
||||
res, err = tx.PseudoToReal(ctx, req.Input)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue