Skip to content

Commit a93a0b2

Browse files
authoredJan 8, 2025··
bfgd: remove pubkey access (#359)
* Remove pubkey access * Add v12 db
1 parent 49bf7f4 commit a93a0b2

File tree

7 files changed

+22
-793
lines changed

7 files changed

+22
-793
lines changed
 

‎api/bfgapi/bfgapi.go

+1-25
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2024 Hemi Labs, Inc.
1+
// Copyright (c) 2024-2025 Hemi Labs, Inc.
22
// Use of this source code is governed by the MIT License,
33
// which can be found in the LICENSE file.
44

@@ -40,10 +40,6 @@ const (
4040
CmdBitcoinInfoResponse = "bfgapi-bitcoin-info-response"
4141
CmdBitcoinUTXOsRequest = "bfgapi-bitcoin-utxos-request"
4242
CmdBitcoinUTXOsResponse = "bfgapi-bitcoin-utxos-response"
43-
CmdAccessPublicKeyCreateRequest = "bfgapi-access-public-key-create-request"
44-
CmdAccessPublicKeyCreateResponse = "bfgapi-access-public-key-create-response"
45-
CmdAccessPublicKeyDeleteRequest = "bfgapi-access-public-key-delete-request"
46-
CmdAccessPublicKeyDeleteResponse = "bfgapi-access-public-key-delete-response"
4743
)
4844

4945
var (
@@ -164,22 +160,6 @@ type BTCNewBlockNotification struct{}
164160

165161
type L2KeystonesNotification struct{}
166162

167-
type AccessPublicKeyCreateRequest struct {
168-
PublicKey string `json:"public_key"` // encoded compressed public key
169-
}
170-
171-
type AccessPublicKeyCreateResponse struct {
172-
Error *protocol.Error `json:"error,omitempty"`
173-
}
174-
175-
type AccessPublicKeyDeleteRequest struct {
176-
PublicKey string `json:"public_key"`
177-
}
178-
179-
type AccessPublicKeyDeleteResponse struct {
180-
Error *protocol.Error `json:"error,omitempty"`
181-
}
182-
183163
type PopTx struct {
184164
BtcTxId api.ByteSlice `json:"btc_tx_id"`
185165
BtcRawTx api.ByteSlice `json:"btc_raw_tx"`
@@ -215,10 +195,6 @@ var commands = map[protocol.Command]reflect.Type{
215195
CmdBitcoinInfoResponse: reflect.TypeOf(BitcoinInfoResponse{}),
216196
CmdBitcoinUTXOsRequest: reflect.TypeOf(BitcoinUTXOsRequest{}),
217197
CmdBitcoinUTXOsResponse: reflect.TypeOf(BitcoinUTXOsResponse{}),
218-
CmdAccessPublicKeyCreateRequest: reflect.TypeOf(AccessPublicKeyCreateRequest{}),
219-
CmdAccessPublicKeyCreateResponse: reflect.TypeOf(AccessPublicKeyCreateResponse{}),
220-
CmdAccessPublicKeyDeleteRequest: reflect.TypeOf(AccessPublicKeyDeleteRequest{}),
221-
CmdAccessPublicKeyDeleteResponse: reflect.TypeOf(AccessPublicKeyDeleteResponse{}),
222198
}
223199

224200
type bfgAPI struct{}

‎cmd/bfgd/bfgd.go

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2024 Hemi Labs, Inc.
1+
// Copyright (c) 2024-2025 Hemi Labs, Inc.
22
// Use of this source code is governed by the MIT License,
33
// which can be found in the LICENSE file.
44

@@ -49,12 +49,6 @@ var (
4949
Help: "electrs max connections",
5050
Print: config.PrintAll,
5151
},
52-
"BFG_PUBLIC_KEY_AUTH": config.Config{
53-
Value: &cfg.PublicKeyAuth,
54-
DefaultValue: false,
55-
Help: "enable enforcing of public key auth handshake",
56-
Print: config.PrintAll,
57-
},
5852
"BFG_BTC_START_HEIGHT": config.Config{
5953
Value: &cfg.BTCStartHeight,
6054
DefaultValue: uint64(0),

‎database/bfgd/database.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2024 Hemi Labs, Inc.
1+
// Copyright (c) 2024-2025 Hemi Labs, Inc.
22
// Use of this source code is governed by the MIT License,
33
// which can be found in the LICENSE file.
44

@@ -38,10 +38,6 @@ type Database interface {
3838

3939
BtcBlockCanonicalHeight(ctx context.Context) (uint64, error)
4040

41-
AccessPublicKeyInsert(ctx context.Context, publicKey *AccessPublicKey) error
42-
AccessPublicKeyExists(ctx context.Context, publicKey *AccessPublicKey) (bool, error)
43-
AccessPublicKeyDelete(ctx context.Context, publicKey *AccessPublicKey) error
44-
4541
BtcTransactionBroadcastRequestInsert(ctx context.Context, serializedTx []byte, txId string) error
4642
BtcTransactionBroadcastRequestGetNext(ctx context.Context, onlyNew bool) ([]byte, error)
4743
BtcTransactionBroadcastRequestConfirmBroadcast(ctx context.Context, txId string) error

‎database/bfgd/postgres/postgres.go

+2-67
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2024 Hemi Labs, Inc.
1+
// Copyright (c) 2024-2025 Hemi Labs, Inc.
22
// Use of this source code is governed by the MIT License,
33
// which can be found in the LICENSE file.
44

@@ -20,7 +20,7 @@ import (
2020
)
2121

2222
const (
23-
bfgdVersion = 11
23+
bfgdVersion = 12
2424

2525
logLevel = "INFO"
2626
verbose = false
@@ -908,71 +908,6 @@ func (p *pgdb) BtcBlockCanonicalHeight(ctx context.Context) (uint64, error) {
908908
return result, nil
909909
}
910910

911-
func (p *pgdb) AccessPublicKeyInsert(ctx context.Context, publicKey *bfgd.AccessPublicKey) error {
912-
log.Tracef("AccessPublicKeyInsert")
913-
defer log.Tracef("AccessPublicKeyInsert exit")
914-
915-
const sql = `
916-
INSERT INTO access_public_keys (
917-
public_key
918-
) VALUES ($1)
919-
`
920-
921-
_, err := p.db.ExecContext(ctx, sql, publicKey.PublicKey)
922-
if err != nil {
923-
var pqErr *pq.Error
924-
if errors.As(err, &pqErr) && pqErr.Constraint == "access_public_keys_pkey" {
925-
return database.DuplicateError("public key already exists")
926-
}
927-
928-
return err
929-
}
930-
931-
return nil
932-
}
933-
934-
func (p *pgdb) AccessPublicKeyExists(ctx context.Context, publicKey *bfgd.AccessPublicKey) (bool, error) {
935-
log.Tracef("AccessPublicKeyExists")
936-
defer log.Tracef("AccessPublicKeyExists exit")
937-
938-
const q = `
939-
SELECT EXISTS (
940-
SELECT * FROM access_public_keys WHERE public_key = $1
941-
)
942-
`
943-
944-
var exists bool
945-
if err := p.db.QueryRowContext(ctx, q, publicKey.PublicKey).Scan(&exists); err != nil {
946-
return false, err
947-
}
948-
949-
return exists, nil
950-
}
951-
952-
func (p *pgdb) AccessPublicKeyDelete(ctx context.Context, publicKey *bfgd.AccessPublicKey) error {
953-
log.Tracef("AccessPublicKeyDelete")
954-
defer log.Tracef("AccessPublicKeyDelete exit")
955-
956-
const q = `
957-
DELETE FROM access_public_keys WHERE public_key = $1
958-
`
959-
960-
res, err := p.db.ExecContext(ctx, q, publicKey.PublicKey)
961-
if err != nil {
962-
return err
963-
}
964-
965-
rows, err := res.RowsAffected()
966-
if err != nil {
967-
return err
968-
}
969-
if rows == 0 {
970-
return database.NotFoundError("public key not found")
971-
}
972-
973-
return nil
974-
}
975-
976911
// BtcBlocksHeightsWithNoChildren returns the heights of blocks stored in the
977912
// database that do not have any children, these represent possible forks that
978913
// have not been handled yet.

‎database/bfgd/scripts/0012.sql

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- Copyright (c) 2025 Hemi Labs, Inc.
2+
-- Use of this source code is governed by the MIT License,
3+
-- which can be found in the LICENSE file.
4+
5+
BEGIN;
6+
7+
UPDATE version SET version = 12;
8+
9+
DROP TABLE access_public_keys;
10+
11+
COMMIT;

0 commit comments

Comments
 (0)
Please sign in to comment.