Skip to content

Commit

Permalink
Merge pull request #109 from SiaFoundation/nate/implement-soft-delete
Browse files Browse the repository at this point in the history
Implement soft delete for spent elements
  • Loading branch information
n8maninger authored May 2, 2024
2 parents 0560d67 + ece0273 commit ec02463
Show file tree
Hide file tree
Showing 14 changed files with 1,879 additions and 489 deletions.
76 changes: 53 additions & 23 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@ run:
# list of build tags, all linters use it. Default is empty list.
build-tags: []

# default is true. Enables skipping of directories:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs-use-default: true

# which files to skip: they will be analyzed, but issues from them
# won't be reported. Default value is empty list, but there is
# no need to include all autogenerated files, we confidently recognize
# autogenerated files. If it's not please let us know.
skip-files: []

# output configuration options
output:
# print lines of code with issue, default is true
Expand All @@ -40,11 +30,14 @@ linters-settings:
## Enabled linters:
govet:
# report about shadowed variables
check-shadowing: false
disable-all: false

golint:
min-confidence: 1.0
tagliatelle:
case:
rules:
json: goCamel
yaml: goCamel


gocritic:
# Which checks should be enabled; can't be combined with 'disabled-checks';
Expand All @@ -56,13 +49,16 @@ linters-settings:
- style
disabled-checks:
# diagnostic
- appendAssign
- commentedOutCode
- uncheckedInlineErr

# style
- httpNoBody
- exitAfterDefer
- ifElseChain
- importShadow
- initClause
- nestingReduce
- octalLiteral
- paramTypeCombine
- ptrToRefParam
Expand All @@ -76,29 +72,63 @@ linters-settings:
revive:
ignore-generated-header: true
rules:
- name: blank-imports
disabled: false
- name: bool-literal-in-expr
disabled: false
- name: confusing-naming
disabled: false
- name: confusing-results
disabled: false
- name: constant-logical-expr
disabled: false
- name: context-as-argument
disabled: false
- name: exported
disabled: false
- name: errorf
disabled: false
- name: if-return
disabled: false
- name: indent-error-flow
disabled: true
- name: increment-decrement
disabled: false
- name: modifies-value-receiver
disabled: true
- name: optimize-operands-order
disabled: false
- name: range-val-in-closure
disabled: false
- name: struct-tag
disabled: false
- name: superfluous-else
disabled: false
- name: time-equal
disabled: false
- name: unexported-naming
disabled: false
- name: unexported-return
disabled: false
- name: unnecessary-stmt
disabled: false
- name: unreachable-code
disabled: false
- name: package-comments
disabled: true

tagliatelle:
case:
rules:
json: goCamel
yaml: goCamel

linters:
disable-all: true
fast: false
enable:
- tagliatelle
- gocritic
- gofmt
- revive
- govet
- misspell
- typecheck
- whitespace
- tagliatelle
- unused
- unparam

issues:
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
Expand Down
1 change: 1 addition & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ type SeedSignRequest struct {
Keys []uint64 `json:"keys"`
}

// RescanResponse contains information about the state of a chain rescan.
type RescanResponse struct {
StartIndex types.ChainIndex `json:"startIndex"`
Index types.ChainIndex `json:"index"`
Expand Down
30 changes: 6 additions & 24 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,7 @@ func TestWalletAdd(t *testing.T) {
}
defer ws.Close()

wm, err := wallet.NewManager(cm, ws, log.Named("wallet"))
if err != nil {
t.Fatal(err)
}
wm := wallet.NewManager(cm, ws, log.Named("wallet"))
defer wm.Close()

c, shutdown := runServer(cm, nil, wm)
Expand Down Expand Up @@ -276,10 +273,7 @@ func TestWallet(t *testing.T) {
})

// create the wallet manager
wm, err := wallet.NewManager(cm, ws, log.Named("wallet"))
if err != nil {
t.Fatal(err)
}
wm := wallet.NewManager(cm, ws, log.Named("wallet"))
defer wm.Close()

// create seed address vault
Expand Down Expand Up @@ -498,10 +492,7 @@ func TestAddresses(t *testing.T) {
}
defer ws.Close()

wm, err := wallet.NewManager(cm, ws, log.Named("wallet"))
if err != nil {
t.Fatal(err)
}
wm := wallet.NewManager(cm, ws, log.Named("wallet"))
defer wm.Close()

sav := wallet.NewSeedAddressVault(wallet.NewSeed(), 0, 20)
Expand Down Expand Up @@ -695,10 +686,7 @@ func TestV2(t *testing.T) {
t.Fatal(err)
}
defer ws.Close()
wm, err := wallet.NewManager(cm, ws, log.Named("wallet"))
if err != nil {
t.Fatal(err)
}
wm := wallet.NewManager(cm, ws, log.Named("wallet"))
defer wm.Close()

c, shutdown := runServer(cm, nil, wm)
Expand Down Expand Up @@ -921,10 +909,7 @@ func TestP2P(t *testing.T) {
t.Fatal(err)
}

wm1, err := wallet.NewManager(cm1, store1, log1.Named("wallet"))
if err != nil {
t.Fatal(err)
}
wm1 := wallet.NewManager(cm1, store1, log1.Named("wallet"))
defer wm1.Close()

l1, err := net.Listen("tcp", ":0")
Expand Down Expand Up @@ -964,10 +949,7 @@ func TestP2P(t *testing.T) {
t.Fatal(err)
}
defer store2.Close()
wm2, err := wallet.NewManager(cm2, store2, log2.Named("wallet"))
if err != nil {
t.Fatal(err)
}
wm2 := wallet.NewManager(cm2, store2, log2.Named("wallet"))
defer wm2.Close()

l2, err := net.Listen("tcp", ":0")
Expand Down
5 changes: 1 addition & 4 deletions cmd/walletd/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,7 @@ func newNode(addr, dir string, chainNetwork string, useUPNP, useBootstrap bool,
}

s := syncer.New(l, cm, ps, header, syncer.WithLogger(log.Named("syncer")))
wm, err := wallet.NewManager(cm, store, log.Named("wallet"))
if err != nil {
return nil, fmt.Errorf("failed to create wallet manager: %w", err)
}
wm := wallet.NewManager(cm, store, log.Named("wallet"))

return &node{
chainStore: bdb,
Expand Down
7 changes: 4 additions & 3 deletions persist/sqlite/addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ func (s *Store) AddressBalance(address types.Address) (balance wallet.Balance, e
// AddressEvents returns the events of a single address.
func (s *Store) AddressEvents(address types.Address, offset, limit int) (events []wallet.Event, err error) {
err = s.transaction(func(tx *txn) error {
const query = `SELECT ev.id, ev.event_id, ev.maturity_height, ev.date_created, ev.height, ev.block_id, ev.event_type, ev.event_data
const query = `SELECT ev.id, ev.event_id, ev.maturity_height, ev.date_created, ci.height, ci.block_id, ev.event_type, ev.event_data
FROM events ev
INNER JOIN event_addresses ea ON (ev.id = ea.event_id)
INNER JOIN sia_addresses sa ON (ea.address_id = sa.id)
INNER JOIN chain_indices ci ON (ev.chain_index_id = ci.id)
WHERE sa.sia_address = $1
ORDER BY ev.maturity_height DESC, ev.id DESC
LIMIT $2 OFFSET $3`
Expand Down Expand Up @@ -52,7 +53,7 @@ func (s *Store) AddressSiacoinOutputs(address types.Address, offset, limit int)
const query = `SELECT se.id, se.siacoin_value, se.merkle_proof, se.leaf_index, se.maturity_height, sa.sia_address
FROM siacoin_elements se
INNER JOIN sia_addresses sa ON (se.address_id = sa.id)
WHERE sa.sia_address=$1
WHERE sa.sia_address=$1 AND se.spent_index_id IS NULL
LIMIT $2 OFFSET $3`

rows, err := tx.Query(query, encode(address), limit, offset)
Expand Down Expand Up @@ -80,7 +81,7 @@ func (s *Store) AddressSiafundOutputs(address types.Address, offset, limit int)
const query = `SELECT se.id, se.leaf_index, se.merkle_proof, se.siafund_value, se.claim_start, sa.sia_address
FROM siafund_elements se
INNER JOIN sia_addresses sa ON (se.address_id = sa.id)
WHERE sa.sia_address = $1
WHERE sa.sia_address = $1 AND se.spent_index_id IS NULL
LIMIT $2 OFFSET $3`

rows, err := tx.Query(query, encode(address), limit, offset)
Expand Down
Loading

0 comments on commit ec02463

Please sign in to comment.