Skip to content

Commit 2b7efa3

Browse files
authored
Merge pull request #244 from CortexFoundation/dev
Dev 2 Master
2 parents cfec042 + 2b94413 commit 2b7efa3

File tree

14 files changed

+802
-216
lines changed

14 files changed

+802
-216
lines changed

client/ctxc_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ func (ec *Client) SendTransaction(ctx context.Context, tx *types.Transaction) er
499499
if err != nil {
500500
return err
501501
}
502-
return ec.c.CallContext(ctx, nil, "ctxc_sendRawTransaction", common.ToHex(data))
502+
return ec.c.CallContext(ctx, nil, "ctxc_sendRawTransaction", hexutil.Encode(data))
503503
}
504504

505505
func toCallArg(msg cortex.CallMsg) interface{} {

core/rawdb/accessors_chain.go

Lines changed: 80 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
"github.com/CortexFoundation/CortexTheseus/common"
2525
"github.com/CortexFoundation/CortexTheseus/core/types"
26+
"github.com/CortexFoundation/CortexTheseus/crypto"
2627
"github.com/CortexFoundation/CortexTheseus/db"
2728
"github.com/CortexFoundation/CortexTheseus/log"
2829
"github.com/CortexFoundation/CortexTheseus/params"
@@ -174,17 +175,23 @@ func WriteFastTrieProgress(db ctxcdb.KeyValueWriter, count uint64) {
174175
// ReadHeaderRLP retrieves a block header in its raw RLP database encoding.
175176
func ReadHeaderRLP(db ctxcdb.Reader, hash common.Hash, number uint64) rlp.RawValue {
176177
data, _ := db.Ancient(freezerHeaderTable, number)
177-
if len(data) == 0 {
178-
data, _ = db.Get(headerKey(number, hash))
179-
// In the background freezer is moving data from leveldb to flatten files.
180-
// So during the first check for ancient db, the data is not yet in there,
181-
// but when we reach into leveldb, the data was already moved. That would
182-
// result in a not found error.
183-
if len(data) == 0 {
184-
data, _ = db.Ancient(freezerHeaderTable, number)
185-
}
178+
if len(data) > 0 && crypto.Keccak256Hash(data) == hash {
179+
return data
180+
}
181+
// Then try to look up the data in leveldb.
182+
data, _ = db.Get(headerKey(number, hash))
183+
if len(data) > 0 {
184+
return data
185+
}
186+
// In the background freezer is moving data from leveldb to flatten files.
187+
// So during the first check for ancient db, the data is not yet in there,
188+
// but when we reach into leveldb, the data was already moved. That would
189+
// result in a not found error.
190+
data, _ = db.Ancient(freezerHeaderTable, number)
191+
if len(data) > 0 && crypto.Keccak256Hash(data) == hash {
192+
return data
186193
}
187-
return data
194+
return nil
188195
}
189196

190197
// HasHeader verifies the existence of a block header corresponding to the hash.
@@ -252,17 +259,29 @@ func deleteHeaderWithoutNumber(db ctxcdb.KeyValueWriter, hash common.Hash, numbe
252259
// ReadBodyRLP retrieves the block body (transactions and uncles) in RLP encoding.
253260
func ReadBodyRLP(db ctxcdb.Reader, hash common.Hash, number uint64) rlp.RawValue {
254261
data, _ := db.Ancient(freezerBodiesTable, number)
255-
if len(data) == 0 {
256-
data, _ = db.Get(blockBodyKey(number, hash))
257-
// In the background freezer is moving data from leveldb to flatten files.
258-
// So during the first check for ancient db, the data is not yet in there,
259-
// but when we reach into leveldb, the data was already moved. That would
260-
// result in a not found error.
261-
if len(data) == 0 {
262-
data, _ = db.Ancient(freezerBodiesTable, number)
262+
if len(data) > 0 {
263+
h, _ := db.Ancient(freezerHashTable, number)
264+
if common.BytesToHash(h) == hash {
265+
return data
266+
}
267+
}
268+
// Then try to look up the data in leveldb.
269+
data, _ = db.Get(blockBodyKey(number, hash))
270+
if len(data) > 0 {
271+
return data
272+
}
273+
// In the background freezer is moving data from leveldb to flatten files.
274+
// So during the first check for ancient db, the data is not yet in there,
275+
// but when we reach into leveldb, the data was already moved. That would
276+
// result in a not found error.
277+
data, _ = db.Ancient(freezerBodiesTable, number)
278+
if len(data) > 0 {
279+
h, _ := db.Ancient(freezerHashTable, number)
280+
if common.BytesToHash(h) == hash {
281+
return data
263282
}
264283
}
265-
return data
284+
return nil
266285
}
267286

268287
// WriteBodyRLP stores an RLP encoded block body into the database.
@@ -316,17 +335,29 @@ func DeleteBody(db ctxcdb.KeyValueWriter, hash common.Hash, number uint64) {
316335
// ReadTdRLP retrieves a block's total difficulty corresponding to the hash in RLP encoding.
317336
func ReadTdRLP(db ctxcdb.Reader, hash common.Hash, number uint64) rlp.RawValue {
318337
data, _ := db.Ancient(freezerDifficultyTable, number)
319-
if len(data) == 0 {
320-
data, _ = db.Get(headerTDKey(number, hash))
321-
// In the background freezer is moving data from leveldb to flatten files.
322-
// So during the first check for ancient db, the data is not yet in there,
323-
// but when we reach into leveldb, the data was already moved. That would
324-
// result in a not found error.
325-
if len(data) == 0 {
326-
data, _ = db.Ancient(freezerDifficultyTable, number)
338+
if len(data) > 0 {
339+
h, _ := db.Ancient(freezerHashTable, number)
340+
if common.BytesToHash(h) == hash {
341+
return data
342+
}
343+
}
344+
// Then try to look up the data in leveldb.
345+
data, _ = db.Get(headerTDKey(number, hash))
346+
if len(data) > 0 {
347+
return data
348+
}
349+
// In the background freezer is moving data from leveldb to flatten files.
350+
// So during the first check for ancient db, the data is not yet in there,
351+
// but when we reach into leveldb, the data was already moved. That would
352+
// result in a not found error.
353+
data, _ = db.Ancient(freezerDifficultyTable, number)
354+
if len(data) > 0 {
355+
h, _ := db.Ancient(freezerHashTable, number)
356+
if common.BytesToHash(h) == hash {
357+
return data
327358
}
328359
}
329-
return data
360+
return nil
330361
}
331362

332363
func ReadTd(db ctxcdb.Reader, hash common.Hash, number uint64) *big.Int {
@@ -372,17 +403,29 @@ func HasReceipts(db ctxcdb.Reader, hash common.Hash, number uint64) bool {
372403

373404
func ReadReceiptsRLP(db ctxcdb.Reader, hash common.Hash, number uint64) rlp.RawValue {
374405
data, _ := db.Ancient(freezerReceiptTable, number)
375-
if len(data) == 0 {
376-
data, _ = db.Get(blockReceiptsKey(number, hash))
377-
// In the background freezer is moving data from leveldb to flatten files.
378-
// So during the first check for ancient db, the data is not yet in there,
379-
// but when we reach into leveldb, the data was already moved. That would
380-
// result in a not found error.
381-
if len(data) == 0 {
382-
data, _ = db.Ancient(freezerReceiptTable, number)
406+
if len(data) > 0 {
407+
h, _ := db.Ancient(freezerHashTable, number)
408+
if common.BytesToHash(h) == hash {
409+
return data
410+
}
411+
}
412+
// Then try to look up the data in leveldb.
413+
data, _ = db.Get(blockReceiptsKey(number, hash))
414+
if len(data) > 0 {
415+
return data
416+
}
417+
// In the background freezer is moving data from leveldb to flatten files.
418+
// So during the first check for ancient db, the data is not yet in there,
419+
// but when we reach into leveldb, the data was already moved. That would
420+
// result in a not found error.
421+
data, _ = db.Ancient(freezerReceiptTable, number)
422+
if len(data) > 0 {
423+
h, _ := db.Ancient(freezerHashTable, number)
424+
if common.BytesToHash(h) == hash {
425+
return data
383426
}
384427
}
385-
return data
428+
return nil
386429
}
387430

388431
// WriteAncientBlock writes entire block data into ancient store and returns the total written size.

event/feed.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,9 @@ type Feed struct {
3939
sendCases caseList // the active set of select cases used by Send
4040

4141
// The inbox holds newly subscribed channels until they are added to sendCases.
42-
mu sync.Mutex
43-
inbox caseList
44-
etype reflect.Type
45-
closed bool
42+
mu sync.Mutex
43+
inbox caseList
44+
etype reflect.Type
4645
}
4746

4847
// This is the index of the first actual subscription channel in sendCases.

inference/defs.template

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package inference
2+
3+
import (
4+
"fmt"
5+
"encoding/binary"
6+
)
7+
8+
func (rdr *NpyReader) GetBytes() ([]byte, error) {
9+
10+
data := make([]byte, rdr.nElt)
11+
err := binary.Read(rdr.r, rdr.Endian, &data)
12+
if err != nil {
13+
return nil, err
14+
}
15+
16+
return data, nil
17+
}
18+
19+
{{- range . }}
20+
// Get{{ .TypeU }} returns the array data as a slice of {{ .TypeL }} values.
21+
func (rdr *NpyReader) Get{{ .TypeU }}() ([]{{ .TypeL }}, error) {
22+
23+
if rdr.Dtype != "{{ .TypeCode }}" {
24+
return nil, fmt.Errorf("Reader does not contain {{ .TypeL }} data")
25+
}
26+
27+
data := make([]{{ .TypeL }}, rdr.nElt)
28+
err := binary.Read(rdr.r, rdr.Endian, &data)
29+
if err != nil {
30+
return nil, err
31+
}
32+
33+
return data, nil
34+
}
35+
{{ end }}
36+
37+
{{- range . }}
38+
// Write{{ .TypeU }} writes a slice of {{ .TypeL }} values in npy format.
39+
func (wtr *NpyWriter) Write{{ .TypeU }}(data []{{ .TypeL }}) error {
40+
41+
err := wtr.writeHeader("{{ .TypeCode }}", len(data))
42+
if err != nil {
43+
return err
44+
}
45+
46+
err = binary.Write(wtr.w, wtr.Endian, data)
47+
if err != nil {
48+
return err
49+
}
50+
51+
wtr.w.Close()
52+
53+
return nil
54+
}
55+
{{ end }}
56+

0 commit comments

Comments
 (0)