Skip to content

Commit 21ebbac

Browse files
committed
Working on cleaning up caching
1 parent 436cec5 commit 21ebbac

25 files changed

+353
-117
lines changed

src/apps/chifra/pkg/cache/cache_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,14 @@ func Example() {
9797
panic(err)
9898
}
9999

100-
if err := store.Write(block, nil); err != nil {
100+
if err := store.Write(block); err != nil {
101101
panic(err)
102102
}
103103

104104
readFromCache := &ExampleBlock{
105105
BlockNumber: 4436721,
106106
}
107-
if err := store.Read(readFromCache, nil); err != nil {
107+
if err := store.Read(readFromCache); err != nil {
108108
panic(err)
109109
}
110110

src/apps/chifra/pkg/cache/store.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ type WriteOptions interface{}
7575
// Write saves value to a location defined by options.Location. If options is nil,
7676
// then FileSystem is used. The value has to implement Locator interface, which
7777
// provides information about in-cache path and ID.
78-
func (s *Store) Write(value Locator, options *WriteOptions) (err error) {
79-
_ = options
78+
func (s *Store) Write(value Locator) (err error) {
8079
if s.readOnly {
8180
err = ErrReadOnly
8281
return
@@ -116,8 +115,7 @@ type ReadOptions interface{}
116115
// Read retrieves value from a location defined by options.Location. If options is nil,
117116
// then FileSystem is used. The value has to implement Locator interface, which
118117
// provides information about in-cache path
119-
func (s *Store) Read(value Locator, options *ReadOptions) (err error) {
120-
_ = options
118+
func (s *Store) Read(value Locator) (err error) {
121119
if itemPath, err := s.resolvePath(value); err != nil {
122120
return err
123121
} else {

src/apps/chifra/pkg/cache/store_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ func TestStoreWrite(t *testing.T) {
4646
}
4747

4848
// Write
49-
if err := cacheStore.Write(value, nil); err != nil {
49+
if err := cacheStore.Write(value); err != nil {
5050
t.Fatal(err)
5151
}
5252

5353
// Retrieve the same value
5454
result := &testStoreData{
5555
Id: "1",
5656
}
57-
if err := cacheStore.Read(result, nil); err != nil {
57+
if err := cacheStore.Read(result); err != nil {
5858
t.Fatal(err)
5959
}
6060
if result.Value != value.Value {

src/apps/chifra/pkg/call/call.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func (call *ContractCall) Call(artFunc func(string, *types.Function) error) (res
194194
Address: call.Address,
195195
Encoding: call.Method.Encoding,
196196
}
197-
if err := call.Conn.Store.Read(results, nil); err == nil {
197+
if err := call.Conn.Store.Read(results); err == nil {
198198
return results, nil
199199
}
200200
}
@@ -263,7 +263,7 @@ func (call *ContractCall) Call(artFunc func(string, *types.Function) error) (res
263263
conn := call.Conn
264264
isFinal := base.IsFinal(conn.LatestBlockTimestamp, blockTs)
265265
if isFinal && conn.StoreWritable() && conn.EnabledMap[walk.Cache_Results] {
266-
_ = conn.Store.Write(results, nil)
266+
_ = conn.Store.Write(results)
267267
}
268268

269269
return results, nil

src/apps/chifra/pkg/ledger/stmnt_from_tx.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func (l *Ledger) GetStatements(conn *rpc.Connection, filter *types.AppearanceFil
2424
TransactionIndex: trans.TransactionIndex,
2525
Address: l.AccountFor,
2626
}
27-
if err := conn.Store.Read(statementGroup, nil); err == nil {
27+
if err := conn.Store.Read(statementGroup); err == nil {
2828
return statementGroup.Statements, nil
2929
}
3030
}
@@ -137,7 +137,7 @@ func (l *Ledger) GetStatements(conn *rpc.Connection, filter *types.AppearanceFil
137137
Address: l.AccountFor,
138138
Statements: statements,
139139
}
140-
_ = conn.Store.Write(statementGroup, nil)
140+
_ = conn.Store.Write(statementGroup)
141141
}
142142

143143
return statements, nil

src/apps/chifra/pkg/rpc/get_block_body.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func (conn *Connection) GetBlockBodyByNumber(bn base.Blknum) (types.Block, error
2222
lightBlock := &types.LightBlock{
2323
BlockNumber: bn,
2424
}
25-
if err := conn.Store.Read(lightBlock, nil); err == nil {
25+
if err := conn.Store.Read(lightBlock); err == nil {
2626
// We need to fill in the actual transactions (from cache hopefully, but
2727
// if not, then from the RPC)
2828
transactions := make([]types.Transaction, 0, len(lightBlock.Transactions))
@@ -84,12 +84,12 @@ func (conn *Connection) GetBlockBodyByNumber(bn base.Blknum) (types.Block, error
8484
block.Transactions[i].Timestamp = block.Timestamp
8585
block.Transactions[i].HasToken = types.IsTokenFunction(block.Transactions[i].Input)
8686
if isFinal && conn.StoreWritable() && conn.EnabledMap[walk.Cache_Transactions] {
87-
_ = conn.Store.Write(&block.Transactions[i], nil)
87+
_ = conn.Store.Write(&block.Transactions[i])
8888
}
8989
}
9090

9191
if isFinal && conn.StoreWritable() && conn.EnabledMap[walk.Cache_Blocks] {
92-
_ = conn.Store.Write(block, nil)
92+
_ = conn.Store.Write(block)
9393
}
9494

9595
// TODO: BOGUS - avoid copy

src/apps/chifra/pkg/rpc/get_block_header.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func (conn *Connection) GetBlockHeaderByNumber(bn base.Blknum) (types.LightBlock
2121
block := types.LightBlock{
2222
BlockNumber: bn,
2323
}
24-
if err := conn.Store.Read(&block, nil); err == nil {
24+
if err := conn.Store.Read(&block); err == nil {
2525
// read was successful
2626
return block, nil
2727
}
@@ -34,7 +34,7 @@ func (conn *Connection) GetBlockHeaderByNumber(bn base.Blknum) (types.LightBlock
3434

3535
isFinal := base.IsFinal(conn.LatestBlockTimestamp, block.Timestamp)
3636
if isFinal && conn.StoreWritable() && conn.EnabledMap[walk.Cache_Blocks] {
37-
_ = conn.Store.Write(block, nil)
37+
_ = conn.Store.Write(block)
3838
}
3939

4040
// TODO: BOGUS - avoid copies

src/apps/chifra/pkg/rpc/get_block_parts.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func (conn *Connection) GetBlockHashByHash(hash string) (base.Hash, error) {
2222
} else {
2323
isFinal := base.IsFinal(conn.LatestBlockTimestamp, block.Timestamp)
2424
if isFinal && conn.StoreWritable() && conn.EnabledMap[walk.Cache_Blocks] {
25-
_ = conn.Store.Write(block, nil)
25+
_ = conn.Store.Write(block)
2626
}
2727
return block.Hash, nil
2828
}
@@ -35,7 +35,7 @@ func (conn *Connection) GetBlockNumberByHash(hash string) (base.Blknum, error) {
3535
} else {
3636
isFinal := base.IsFinal(conn.LatestBlockTimestamp, block.Timestamp)
3737
if isFinal && conn.StoreWritable() && conn.EnabledMap[walk.Cache_Blocks] {
38-
_ = conn.Store.Write(block, nil)
38+
_ = conn.Store.Write(block)
3939
}
4040
return block.BlockNumber, nil
4141
}

src/apps/chifra/pkg/rpc/get_log.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func (conn *Connection) GetLogsByNumber(bn base.Blknum, ts base.Timestamp) ([]ty
1818
BlockNumber: bn,
1919
TransactionIndex: base.NOPOSN,
2020
}
21-
if err := conn.Store.Read(logGroup, nil); err == nil {
21+
if err := conn.Store.Read(logGroup); err == nil {
2222
return logGroup.Logs, nil
2323
}
2424
}
@@ -38,7 +38,7 @@ func (conn *Connection) GetLogsByNumber(bn base.Blknum, ts base.Timestamp) ([]ty
3838
TransactionIndex: base.NOPOSN,
3939
Logs: logs,
4040
}
41-
if err = conn.Store.Write(logGroup, nil); err != nil {
41+
if err = conn.Store.Write(logGroup); err != nil {
4242
logger.Warn("Failed to write logs to cache", err)
4343
}
4444
}

src/apps/chifra/pkg/rpc/get_receipt.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (conn *Connection) GetReceiptNoTimestamp(bn base.Blknum, txid base.Txnum) (
3838
BlockNumber: bn,
3939
TransactionIndex: txid,
4040
}
41-
if err := conn.Store.Read(tx, nil); err == nil {
41+
if err := conn.Store.Read(tx); err == nil {
4242
// success
4343
if tx.Receipt == nil {
4444
return receipt, nil
@@ -77,7 +77,7 @@ func (conn *Connection) GetReceiptsByNumber(bn base.Blknum, ts base.Timestamp) (
7777
BlockNumber: bn,
7878
TransactionIndex: base.NOPOSN,
7979
}
80-
if err := conn.Store.Read(receiptGroup, nil); err == nil {
80+
if err := conn.Store.Read(receiptGroup); err == nil {
8181
receiptMap := make(map[base.Txnum]*types.Receipt, len(receiptGroup.Receipts))
8282
for index := 0; index < len(receiptGroup.Receipts); index++ {
8383
pReceipt := &receiptGroup.Receipts[index]
@@ -97,7 +97,7 @@ func (conn *Connection) GetReceiptsByNumber(bn base.Blknum, ts base.Timestamp) (
9797
TransactionIndex: base.NOPOSN,
9898
Receipts: receipts,
9999
}
100-
if err = conn.Store.Write(receiptGroup, nil); err != nil {
100+
if err = conn.Store.Write(receiptGroup); err != nil {
101101
logger.Warn("Failed to write receipts to cache", err)
102102
}
103103
}

src/apps/chifra/pkg/rpc/get_state.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func (conn *Connection) GetState(fieldBits types.StatePart, address base.Address
2424
BlockNumber: blockNumber,
2525
Address: address,
2626
}
27-
if err := conn.Store.Read(state, nil); err == nil {
27+
if err := conn.Store.Read(state); err == nil {
2828
if state.Parts&fieldBits == fieldBits {
2929
// we have what we need
3030
return state, nil
@@ -143,7 +143,7 @@ func (conn *Connection) GetState(fieldBits types.StatePart, address base.Address
143143

144144
isFinal := base.IsFinal(conn.LatestBlockTimestamp, blockTs)
145145
if isFinal && conn.StoreWritable() && conn.EnabledMap[walk.Cache_State] {
146-
_ = conn.Store.Write(state, nil)
146+
_ = conn.Store.Write(state)
147147
}
148148

149149
if filters.BalanceCheck != nil {

src/apps/chifra/pkg/rpc/get_traces.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func (conn *Connection) GetTracesByBlockNumber(bn base.Blknum) ([]types.Trace, e
2121
BlockNumber: bn,
2222
TransactionIndex: base.NOPOSN, // no tx id means we're storing the whole block
2323
}
24-
if err := conn.Store.Read(traceGroup, nil); err == nil {
24+
if err := conn.Store.Read(traceGroup); err == nil {
2525
return traceGroup.Traces, nil
2626
}
2727
}
@@ -69,7 +69,7 @@ func (conn *Connection) GetTracesByBlockNumber(bn base.Blknum) ([]types.Trace, e
6969
BlockNumber: bn,
7070
TransactionIndex: base.NOPOSN,
7171
}
72-
_ = conn.Store.Write(traceGroup, nil)
72+
_ = conn.Store.Write(traceGroup)
7373
}
7474
return *traces, nil
7575
}
@@ -84,7 +84,7 @@ func (conn *Connection) GetTracesByTransactionHash(txHash string, transaction *t
8484
TransactionIndex: transaction.TransactionIndex,
8585
Traces: make([]types.Trace, 0, len(transaction.Traces)),
8686
}
87-
if err := conn.Store.Read(traceGroup, nil); err == nil {
87+
if err := conn.Store.Read(traceGroup); err == nil {
8888
return traceGroup.Traces, nil
8989
}
9090
}
@@ -135,7 +135,7 @@ func (conn *Connection) GetTracesByTransactionHash(txHash string, transaction *t
135135
TransactionIndex: transaction.TransactionIndex,
136136
Traces: *traces,
137137
}
138-
_ = conn.Store.Write(traceGroup, nil)
138+
_ = conn.Store.Write(traceGroup)
139139
}
140140
}
141141

src/apps/chifra/pkg/rpc/get_traces_parts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func (conn *Connection) GetTracesByTransactionId(bn base.Blknum, txid base.Txnum
1717
BlockNumber: bn,
1818
TransactionIndex: txid,
1919
}
20-
if err := conn.Store.Read(traceGroup, nil); err == nil {
20+
if err := conn.Store.Read(traceGroup); err == nil {
2121
return traceGroup.Traces, nil
2222
}
2323
}

src/apps/chifra/pkg/rpc/get_transaction.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func (conn *Connection) GetTransactionByNumberAndId(bn base.Blknum, txid base.Tx
2020
BlockNumber: bn,
2121
TransactionIndex: txid,
2222
}
23-
if err := conn.Store.Read(tx, nil); err == nil {
23+
if err := conn.Store.Read(tx); err == nil {
2424
// success
2525
return tx, nil
2626
}
@@ -45,7 +45,7 @@ func (conn *Connection) GetTransactionByNumberAndId(bn base.Blknum, txid base.Tx
4545

4646
isFinal := base.IsFinal(conn.LatestBlockTimestamp, blockTs)
4747
if isFinal && conn.StoreWritable() && conn.EnabledMap[walk.Cache_Transactions] {
48-
_ = conn.Store.Write(trans, nil)
48+
_ = conn.Store.Write(trans)
4949
}
5050

5151
return trans, nil
@@ -69,7 +69,7 @@ func (conn *Connection) GetTransactionByAppearance(app *types.Appearance, fetchT
6969
BlockNumber: bn,
7070
TransactionIndex: txid,
7171
}
72-
if err := conn.Store.Read(tx, nil); err == nil {
72+
if err := conn.Store.Read(tx); err == nil {
7373
// success
7474
if fetchTraces {
7575
traces, err := conn.GetTracesByTransactionHash(tx.Hash.Hex(), tx)
@@ -90,7 +90,7 @@ func (conn *Connection) GetTransactionByAppearance(app *types.Appearance, fetchT
9090
tx.Timestamp = blockTs
9191
isFinal := base.IsFinal(conn.LatestBlockTimestamp, blockTs)
9292
if isFinal && conn.StoreWritable() && conn.EnabledMap[walk.Cache_Transactions] {
93-
_ = conn.Store.Write(tx, nil)
93+
_ = conn.Store.Write(tx)
9494
}
9595
return tx, nil
9696
}
@@ -101,7 +101,7 @@ func (conn *Connection) GetTransactionByAppearance(app *types.Appearance, fetchT
101101
tx.Timestamp = blockTs
102102
isFinal := base.IsFinal(conn.LatestBlockTimestamp, blockTs)
103103
if isFinal && conn.StoreWritable() && conn.EnabledMap[walk.Cache_Transactions] {
104-
_ = conn.Store.Write(tx, nil)
104+
_ = conn.Store.Write(tx)
105105
}
106106
return tx, nil
107107
}
@@ -112,7 +112,7 @@ func (conn *Connection) GetTransactionByAppearance(app *types.Appearance, fetchT
112112
tx.Timestamp = blockTs
113113
isFinal := base.IsFinal(conn.LatestBlockTimestamp, blockTs)
114114
if isFinal && conn.StoreWritable() && conn.EnabledMap[walk.Cache_Transactions] {
115-
_ = conn.Store.Write(tx, nil)
115+
_ = conn.Store.Write(tx)
116116
}
117117
return tx, nil
118118
}
@@ -123,7 +123,7 @@ func (conn *Connection) GetTransactionByAppearance(app *types.Appearance, fetchT
123123
tx.Timestamp = blockTs
124124
isFinal := base.IsFinal(conn.LatestBlockTimestamp, blockTs)
125125
if isFinal && conn.StoreWritable() && conn.EnabledMap[walk.Cache_Transactions] {
126-
_ = conn.Store.Write(tx, nil)
126+
_ = conn.Store.Write(tx)
127127
}
128128
return tx, nil
129129
}
@@ -147,7 +147,7 @@ func (conn *Connection) GetTransactionByAppearance(app *types.Appearance, fetchT
147147

148148
isFinal := base.IsFinal(conn.LatestBlockTimestamp, blockTs)
149149
if isFinal && conn.StoreWritable() && conn.EnabledMap[walk.Cache_Transactions] {
150-
_ = conn.Store.Write(trans, nil)
150+
_ = conn.Store.Write(trans)
151151
}
152152

153153
if fetchTraces {

src/apps/chifra/pkg/rpc/get_withdrawal.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (conn *Connection) GetWithdrawalsByNumber(bn base.Blknum) ([]types.Withdraw
4040
BlockNumber: bn,
4141
TransactionIndex: base.NOPOSN,
4242
}
43-
if err := conn.Store.Read(withdrawalGroup, nil); err == nil {
43+
if err := conn.Store.Read(withdrawalGroup); err == nil {
4444
return withdrawalGroup.Withdrawals, nil
4545
}
4646
}
@@ -55,7 +55,7 @@ func (conn *Connection) GetWithdrawalsByNumber(bn base.Blknum) ([]types.Withdraw
5555
TransactionIndex: base.NOPOSN,
5656
Withdrawals: withdrawals,
5757
}
58-
if err = conn.Store.Write(withdrawalGroup, nil); err != nil {
58+
if err = conn.Store.Write(withdrawalGroup); err != nil {
5959
logger.Warn("Failed to write withdrawals to cache", err)
6060
}
6161
}

src/apps/chifra/pkg/types/filter.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package types
66

77
import (
8-
"sort"
98
"strings"
109

1110
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
@@ -127,24 +126,3 @@ func (f *AppearanceFilter) ApplyLogFilter(log *Log, addrArray []base.Address) bo
127126
}
128127
return false
129128
}
130-
131-
type AppearanceSort int
132-
133-
const (
134-
NotSorted AppearanceSort = iota
135-
Sorted
136-
Reversed
137-
)
138-
139-
func (f *AppearanceFilter) Sort(fromDisc []AppRecord) {
140-
if f.sortBy == Sorted || f.sortBy == Reversed {
141-
sort.Slice(fromDisc, func(i, j int) bool {
142-
if f.sortBy == Reversed {
143-
i, j = j, i
144-
}
145-
si := (base.Blknum(fromDisc[i].BlockNumber) << 32) + base.Blknum(fromDisc[i].TransactionIndex)
146-
sj := (base.Blknum(fromDisc[j].BlockNumber) << 32) + base.Blknum(fromDisc[j].TransactionIndex)
147-
return si < sj
148-
})
149-
}
150-
}

0 commit comments

Comments
 (0)