Skip to content

Commit

Permalink
Merge pull request #244 from CortexFoundation/dev
Browse files Browse the repository at this point in the history
Dev 2 Master
  • Loading branch information
ucwong authored Nov 21, 2019
2 parents cfec042 + 2b94413 commit 2b7efa3
Show file tree
Hide file tree
Showing 14 changed files with 802 additions and 216 deletions.
2 changes: 1 addition & 1 deletion client/ctxc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ func (ec *Client) SendTransaction(ctx context.Context, tx *types.Transaction) er
if err != nil {
return err
}
return ec.c.CallContext(ctx, nil, "ctxc_sendRawTransaction", common.ToHex(data))
return ec.c.CallContext(ctx, nil, "ctxc_sendRawTransaction", hexutil.Encode(data))
}

func toCallArg(msg cortex.CallMsg) interface{} {
Expand Down
117 changes: 80 additions & 37 deletions core/rawdb/accessors_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/CortexFoundation/CortexTheseus/common"
"github.com/CortexFoundation/CortexTheseus/core/types"
"github.com/CortexFoundation/CortexTheseus/crypto"
"github.com/CortexFoundation/CortexTheseus/db"
"github.com/CortexFoundation/CortexTheseus/log"
"github.com/CortexFoundation/CortexTheseus/params"
Expand Down Expand Up @@ -174,17 +175,23 @@ func WriteFastTrieProgress(db ctxcdb.KeyValueWriter, count uint64) {
// ReadHeaderRLP retrieves a block header in its raw RLP database encoding.
func ReadHeaderRLP(db ctxcdb.Reader, hash common.Hash, number uint64) rlp.RawValue {
data, _ := db.Ancient(freezerHeaderTable, number)
if len(data) == 0 {
data, _ = db.Get(headerKey(number, hash))
// In the background freezer is moving data from leveldb to flatten files.
// So during the first check for ancient db, the data is not yet in there,
// but when we reach into leveldb, the data was already moved. That would
// result in a not found error.
if len(data) == 0 {
data, _ = db.Ancient(freezerHeaderTable, number)
}
if len(data) > 0 && crypto.Keccak256Hash(data) == hash {
return data
}
// Then try to look up the data in leveldb.
data, _ = db.Get(headerKey(number, hash))
if len(data) > 0 {
return data
}
// In the background freezer is moving data from leveldb to flatten files.
// So during the first check for ancient db, the data is not yet in there,
// but when we reach into leveldb, the data was already moved. That would
// result in a not found error.
data, _ = db.Ancient(freezerHeaderTable, number)
if len(data) > 0 && crypto.Keccak256Hash(data) == hash {
return data
}
return data
return nil
}

// HasHeader verifies the existence of a block header corresponding to the hash.
Expand Down Expand Up @@ -252,17 +259,29 @@ func deleteHeaderWithoutNumber(db ctxcdb.KeyValueWriter, hash common.Hash, numbe
// ReadBodyRLP retrieves the block body (transactions and uncles) in RLP encoding.
func ReadBodyRLP(db ctxcdb.Reader, hash common.Hash, number uint64) rlp.RawValue {
data, _ := db.Ancient(freezerBodiesTable, number)
if len(data) == 0 {
data, _ = db.Get(blockBodyKey(number, hash))
// In the background freezer is moving data from leveldb to flatten files.
// So during the first check for ancient db, the data is not yet in there,
// but when we reach into leveldb, the data was already moved. That would
// result in a not found error.
if len(data) == 0 {
data, _ = db.Ancient(freezerBodiesTable, number)
if len(data) > 0 {
h, _ := db.Ancient(freezerHashTable, number)
if common.BytesToHash(h) == hash {
return data
}
}
// Then try to look up the data in leveldb.
data, _ = db.Get(blockBodyKey(number, hash))
if len(data) > 0 {
return data
}
// In the background freezer is moving data from leveldb to flatten files.
// So during the first check for ancient db, the data is not yet in there,
// but when we reach into leveldb, the data was already moved. That would
// result in a not found error.
data, _ = db.Ancient(freezerBodiesTable, number)
if len(data) > 0 {
h, _ := db.Ancient(freezerHashTable, number)
if common.BytesToHash(h) == hash {
return data
}
}
return data
return nil
}

// WriteBodyRLP stores an RLP encoded block body into the database.
Expand Down Expand Up @@ -316,17 +335,29 @@ func DeleteBody(db ctxcdb.KeyValueWriter, hash common.Hash, number uint64) {
// ReadTdRLP retrieves a block's total difficulty corresponding to the hash in RLP encoding.
func ReadTdRLP(db ctxcdb.Reader, hash common.Hash, number uint64) rlp.RawValue {
data, _ := db.Ancient(freezerDifficultyTable, number)
if len(data) == 0 {
data, _ = db.Get(headerTDKey(number, hash))
// In the background freezer is moving data from leveldb to flatten files.
// So during the first check for ancient db, the data is not yet in there,
// but when we reach into leveldb, the data was already moved. That would
// result in a not found error.
if len(data) == 0 {
data, _ = db.Ancient(freezerDifficultyTable, number)
if len(data) > 0 {
h, _ := db.Ancient(freezerHashTable, number)
if common.BytesToHash(h) == hash {
return data
}
}
// Then try to look up the data in leveldb.
data, _ = db.Get(headerTDKey(number, hash))
if len(data) > 0 {
return data
}
// In the background freezer is moving data from leveldb to flatten files.
// So during the first check for ancient db, the data is not yet in there,
// but when we reach into leveldb, the data was already moved. That would
// result in a not found error.
data, _ = db.Ancient(freezerDifficultyTable, number)
if len(data) > 0 {
h, _ := db.Ancient(freezerHashTable, number)
if common.BytesToHash(h) == hash {
return data
}
}
return data
return nil
}

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

func ReadReceiptsRLP(db ctxcdb.Reader, hash common.Hash, number uint64) rlp.RawValue {
data, _ := db.Ancient(freezerReceiptTable, number)
if len(data) == 0 {
data, _ = db.Get(blockReceiptsKey(number, hash))
// In the background freezer is moving data from leveldb to flatten files.
// So during the first check for ancient db, the data is not yet in there,
// but when we reach into leveldb, the data was already moved. That would
// result in a not found error.
if len(data) == 0 {
data, _ = db.Ancient(freezerReceiptTable, number)
if len(data) > 0 {
h, _ := db.Ancient(freezerHashTable, number)
if common.BytesToHash(h) == hash {
return data
}
}
// Then try to look up the data in leveldb.
data, _ = db.Get(blockReceiptsKey(number, hash))
if len(data) > 0 {
return data
}
// In the background freezer is moving data from leveldb to flatten files.
// So during the first check for ancient db, the data is not yet in there,
// but when we reach into leveldb, the data was already moved. That would
// result in a not found error.
data, _ = db.Ancient(freezerReceiptTable, number)
if len(data) > 0 {
h, _ := db.Ancient(freezerHashTable, number)
if common.BytesToHash(h) == hash {
return data
}
}
return data
return nil
}

// WriteAncientBlock writes entire block data into ancient store and returns the total written size.
Expand Down
7 changes: 3 additions & 4 deletions event/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ type Feed struct {
sendCases caseList // the active set of select cases used by Send

// The inbox holds newly subscribed channels until they are added to sendCases.
mu sync.Mutex
inbox caseList
etype reflect.Type
closed bool
mu sync.Mutex
inbox caseList
etype reflect.Type
}

// This is the index of the first actual subscription channel in sendCases.
Expand Down
56 changes: 56 additions & 0 deletions inference/defs.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package inference

import (
"fmt"
"encoding/binary"
)

func (rdr *NpyReader) GetBytes() ([]byte, error) {

data := make([]byte, rdr.nElt)
err := binary.Read(rdr.r, rdr.Endian, &data)
if err != nil {
return nil, err
}

return data, nil
}

{{- range . }}
// Get{{ .TypeU }} returns the array data as a slice of {{ .TypeL }} values.
func (rdr *NpyReader) Get{{ .TypeU }}() ([]{{ .TypeL }}, error) {

if rdr.Dtype != "{{ .TypeCode }}" {
return nil, fmt.Errorf("Reader does not contain {{ .TypeL }} data")
}

data := make([]{{ .TypeL }}, rdr.nElt)
err := binary.Read(rdr.r, rdr.Endian, &data)
if err != nil {
return nil, err
}

return data, nil
}
{{ end }}

{{- range . }}
// Write{{ .TypeU }} writes a slice of {{ .TypeL }} values in npy format.
func (wtr *NpyWriter) Write{{ .TypeU }}(data []{{ .TypeL }}) error {

err := wtr.writeHeader("{{ .TypeCode }}", len(data))
if err != nil {
return err
}

err = binary.Write(wtr.w, wtr.Endian, data)
if err != nil {
return err
}

wtr.w.Close()

return nil
}
{{ end }}

Loading

0 comments on commit 2b7efa3

Please sign in to comment.