Skip to content

Commit

Permalink
Merge pull request #1328 from CortexFoundation/lazy
Browse files Browse the repository at this point in the history
Lazy robot
  • Loading branch information
ucwong authored Oct 16, 2022
2 parents 356769d + 3fcefdc commit eda1969
Show file tree
Hide file tree
Showing 294 changed files with 64,969 additions and 2,525 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ clean-all: clean-clib clean
devtools:
env GOBIN= go get -u golang.org/x/tools/cmd/stringer
env GOBIN= go get -u github.com/fjl/gencodec
env GOBIN= go get -u github.com/golang/protobuf/protoc-gen-go
#env GOBIN= go get -u github.com/golang/protobuf/protoc-gen-go
env GOGIN= go get -u google.golang.org/protobuf/cmd/protoc-gen-go@latest
env GOBIN= go install ./cmd/abigen
@type "npm" 2> /dev/null || echo 'Please install node.js and npm'
@type "solc" 2> /dev/null || echo 'Please install solc'
Expand Down
21 changes: 10 additions & 11 deletions build/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,18 @@ Usage: go run build/ci.go <command> <command flags/arguments>
Available commands are:
install [ -arch architecture ] [ -cc compiler ] [ packages... ] -- builds packages and executables
test [ -coverage ] [ packages... ] -- runs the tests
lint -- runs certain pre-selected linters
archive [ -arch architecture ] [ -type zip|tar ] [ -signer key-envvar ] [ -signify key-envvar ] [ -upload dest ] -- archives build artifacts
importkeys -- imports signing keys from env
debsrc [ -signer key-id ] [ -upload dest ] -- creates a debian source package
nsis -- creates a Windows NSIS installer
aar [ -local ] [ -sign key-id ] [-deploy repo] [ -upload dest ] -- creates an Android archive
xcode [ -local ] [ -sign key-id ] [-deploy repo] [ -upload dest ] -- creates an iOS XCode framework
purge [ -store blobstore ] [ -days threshold ] -- purges old archives from the blobstore
install [ -arch architecture ] [ -cc compiler ] [ packages... ] -- builds packages and executables
test [ -coverage ] [ packages... ] -- runs the tests
lint -- runs certain pre-selected linters
archive [ -arch architecture ] [ -type zip|tar ] [ -signer key-envvar ] [ -signify key-envvar ] [ -upload dest ] -- archives build artifacts
importkeys -- imports signing keys from env
debsrc [ -signer key-id ] [ -upload dest ] -- creates a debian source package
nsis -- creates a Windows NSIS installer
aar [ -local ] [ -sign key-id ] [-deploy repo] [ -upload dest ] -- creates an Android archive
xcode [ -local ] [ -sign key-id ] [-deploy repo] [ -upload dest ] -- creates an iOS XCode framework
purge [ -store blobstore ] [ -days threshold ] -- purges old archives from the blobstore
For all commands, -n prevents execution of external programs (dry run mode).
*/
package main

Expand Down
3 changes: 2 additions & 1 deletion build/tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ package tools
import (
// Tool imports for go:generate.
_ "github.com/fjl/gencodec"
_ "github.com/golang/protobuf/protoc-gen-go"
//_ "github.com/golang/protobuf/protoc-gen-go"
_ "golang.org/x/tools/cmd/stringer"
_ "google.golang.org/protobuf/cmd/protoc-gen-go"

// Tool imports for mobile build.
_ "golang.org/x/mobile/cmd/gobind"
Expand Down
4 changes: 2 additions & 2 deletions cmd/cortex/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,12 +420,12 @@ func removeDB(ctx *cli.Context) error {
log.Info("Full node ancient database missing", "path", path)
}

path = stack.ResolvePath("../storage")
/*path = stack.ResolvePath("../storage")
if common.FileExist(path) {
confirmAndRemoveDB(path, "full node file storage")
} else {
log.Info("Full node file storage missing", "path", path)
}
}*/
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/cortex/cvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func cvmServer(ctx *cli.Context) error {
log.Warn("fsCfg.DataDir", "fsCfg.DataDir", fsCfg.DataDir)
fsCfg.IpcPath = filepath.Join(ctx.GlobalString(CVMCortexDir.Name), "cortex.ipc")
log.Debug("Cvm Server", "fs", fsCfg, "storage", ctx.GlobalString(utils.StorageDirFlag.Name), "ipc path", fsCfg.IpcPath)
storagefs, fsErr := torrentfs.New(&fsCfg, true, false, true)
storagefs, fsErr := torrentfs.New(&fsCfg, false, false, true)
if fsErr != nil {
return errors.New("fs start failed")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1727,7 +1727,7 @@ func RegisterShhService(stack *node.Node, cfg *whisper.Config) {
func RegisterStorageService(stack *node.Node, cfg *torrentfs.Config) {
if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
//return torrentfs.New(cfg, true, false, downloader.FastSync == mode)
return torrentfs.New(cfg, true, false, false)
return torrentfs.New(cfg, false, false, false)
}); err != nil {
Fatalf("Failed to register the storage service: %v", err)
}
Expand Down
23 changes: 1 addition & 22 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ type BlockChain struct {
processor Processor // Block transaction processor interface
vmConfig vm.Config

badBlocks *lru.Cache // Bad block cache
shouldPreserve func(*types.Block) bool // Function used to determine whether should preserve the given block.
writeLegacyJournal bool // Testing flag used to flush the snapshot journal in legacy format.
utcNow int64
Expand All @@ -235,7 +234,6 @@ func NewBlockChain(db ctxcdb.Database, cacheConfig *CacheConfig, chainConfig *pa
blockCache, _ := lru.New(blockCacheLimit)
txLookupCache, _ := lru.New(txLookupCacheLimit)
futureBlocks, _ := lru.New(maxFutureBlocks)
badBlocks, _ := lru.New(badBlockLimit)

bc := &BlockChain{
chainConfig: chainConfig,
Expand All @@ -258,7 +256,6 @@ func NewBlockChain(db ctxcdb.Database, cacheConfig *CacheConfig, chainConfig *pa
futureBlocks: futureBlocks,
engine: engine,
vmConfig: vmConfig,
badBlocks: badBlocks,
}
bc.validator = NewBlockValidator(chainConfig, bc, engine)
bc.prefetcher = newStatePrefetcher(chainConfig, bc, engine)
Expand Down Expand Up @@ -2244,30 +2241,12 @@ func (bc *BlockChain) maintainTxIndex() {
}
}

// BadBlocks returns a list of the last 'bad blocks' that the client has seen on the network
func (bc *BlockChain) BadBlocks() []*types.Block {
blocks := make([]*types.Block, 0, bc.badBlocks.Len())
for _, hash := range bc.badBlocks.Keys() {
if blk, exist := bc.badBlocks.Peek(hash); exist {
block := blk.(*types.Block)
blocks = append(blocks, block)
}
}
return blocks
}

// addBadBlock adds a bad block to the bad-block LRU cache
func (bc *BlockChain) addBadBlock(block *types.Block) {
bc.badBlocks.Add(block.Hash(), block)
}

// reportBlock logs a bad block error.
func (bc *BlockChain) reportBlock(block *types.Block, receipts types.Receipts, err error) {
if errors.Is(err, vm.ErrRuntime) {
return
}

bc.addBadBlock(block)
rawdb.WriteBadBlock(bc.db, block)

var receiptString string
for i, receipt := range receipts {
Expand Down
20 changes: 14 additions & 6 deletions core/chain_indexer_test.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
// Copyright 2018 The CortexTheseus Authors
// This file is part of the CortexFoundation library.
// This file is part of the CortexTheseus library.
//
// The CortexFoundation library is free software: you can redistribute it and/or modify
// The CortexTheseus library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The CortexFoundation library is distributed in the hope that it will be useful,
// The CortexTheseus library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the CortexFoundation library. If not, see <http://www.gnu.org/licenses/>.
// along with the CortexTheseus library. If not, see <http://www.gnu.org/licenses/>.

package core

import (
"context"
"errors"
"fmt"
"math/big"
"math/rand"
Expand Down Expand Up @@ -203,7 +204,7 @@ func (b *testChainIndexBackend) assertBlocks(headNum, failNum uint64) (uint64, b
}

func (b *testChainIndexBackend) reorg(headNum uint64) uint64 {
firstChanged := headNum / b.indexer.sectionSize
firstChanged := (headNum + 1) / b.indexer.sectionSize
if firstChanged < b.stored {
b.stored = firstChanged
}
Expand All @@ -224,7 +225,10 @@ func (b *testChainIndexBackend) Process(ctx context.Context, header *types.Heade
//t.processCh <- header.Number.Uint64()
select {
case <-time.After(10 * time.Second):
b.t.Fatal("Unexpected call to Process")
b.t.Error("Unexpected call to Process")
// Can't use Fatal since this is not the test's goroutine.
// Returning error stops the chainIndexer's updateLoop
return errors.New("Unexpected call to Process")
case b.processCh <- header.Number.Uint64():
}
return nil
Expand All @@ -236,3 +240,7 @@ func (b *testChainIndexBackend) Commit() error {
}
return nil
}

func (b *testChainIndexBackend) Prune(threshold uint64) error {
return nil
}
33 changes: 21 additions & 12 deletions ctxc/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,23 +330,32 @@ type BadBlockArgs struct {

// GetBadBlocks returns a list of the last 'bad blocks' that the client has seen on the network
// and returns them as a JSON list of block-hashes
// GetBadBlocks returns a list of the last 'bad blocks' that the client has seen on the network
// and returns them as a JSON list of block hashes.
func (api *PrivateDebugAPI) GetBadBlocks(ctx context.Context) ([]*BadBlockArgs, error) {
blocks := api.ctxc.BlockChain().BadBlocks()
results := make([]*BadBlockArgs, len(blocks))

var err error
for i, block := range blocks {
results[i] = &BadBlockArgs{
Hash: block.Hash(),
}
var (
err error
blocks = rawdb.ReadAllBadBlocks(api.ctxc.chainDb)
results = make([]*BadBlockArgs, 0, len(blocks))
)
for _, block := range blocks {
var (
blockRlp string
blockJSON map[string]interface{}
)
if rlpBytes, err := rlp.EncodeToBytes(block); err != nil {
results[i].RLP = err.Error() // Hacky, but hey, it works
blockRlp = err.Error() // Hacky, but hey, it works
} else {
results[i].RLP = fmt.Sprintf("0x%x", rlpBytes)
blockRlp = fmt.Sprintf("%#x", rlpBytes)
}
if results[i].Block, err = ctxcapi.RPCMarshalBlock(block, true, true); err != nil {
results[i].Block = map[string]interface{}{"error": err.Error()}
if blockJSON, err = ctxcapi.RPCMarshalBlock(block, true, true); err != nil {
blockJSON = map[string]interface{}{"error": err.Error()}
}
results = append(results, &BadBlockArgs{
Hash: block.Hash(),
RLP: blockRlp,
Block: blockJSON,
})
}
return results, nil
}
Expand Down
5 changes: 3 additions & 2 deletions ctxc/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ func (ctxc *Cortex) startCtxcEntryUpdate(ln *enode.LocalNode) {
}

func (ctxc *Cortex) currentCtxcEntry() *ctxcEntry {
return &ctxcEntry{ForkID: forkid.NewID(ctxc.blockchain.Config(), ctxc.blockchain.Genesis().Hash(),
ctxc.blockchain.CurrentHeader().Number.Uint64())}
return &ctxcEntry{
ForkID: forkid.NewID(ctxc.blockchain.Config(), ctxc.blockchain.Genesis().Hash(),
ctxc.blockchain.CurrentHeader().Number.Uint64())}
}

// setupDiscovery creates the node discovery source for the ctxc protocol.
Expand Down
9 changes: 0 additions & 9 deletions ctxc/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,15 +359,6 @@ func (d *Downloader) synchronise(id string, hash common.Hash, td *big.Int, mode
default:
}
}
for _, ch := range []chan dataPack{d.headerCh, d.bodyCh, d.receiptCh} {
for empty := false; !empty; {
select {
case <-ch:
default:
empty = true
}
}
}
for empty := false; !empty; {
select {
case <-d.headerProcCh:
Expand Down
17 changes: 12 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.4.1
github.com/CortexFoundation/inference v1.0.2-0.20220421072809-9c87efb8a557
github.com/CortexFoundation/statik v0.0.0-20210315012922-8bb8a7b5dc66
github.com/CortexFoundation/torrentfs v1.0.31-0.20221010073023-f81f304f1fce
github.com/CortexFoundation/torrentfs v1.0.32-0.20221016185648-83ac5c23513d
github.com/VictoriaMetrics/fastcache v1.12.0
github.com/arsham/figurine v1.2.0
github.com/aws/aws-sdk-go-v2 v1.16.16
Expand All @@ -26,12 +26,11 @@ require (
github.com/fogleman/ease v0.0.0-20170301025033-8da417bf1776
github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08
github.com/go-stack/stack v1.8.1
github.com/golang/protobuf v1.5.2
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb
github.com/google/gofuzz v1.2.1-0.20210524182514-9eed411d8615
github.com/google/uuid v1.3.0
github.com/gorilla/websocket v1.5.0
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d
github.com/hashicorp/golang-lru v0.5.5-0.20221011183528-d4900dc688bf
github.com/holiman/bloomfilter/v2 v2.0.3
github.com/holiman/uint256 v1.2.1
github.com/huin/goupnp v1.0.4-0.20220613170603-23b555710578
Expand Down Expand Up @@ -64,6 +63,7 @@ require (
golang.org/x/text v0.3.7
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af
golang.org/x/tools v0.1.13-0.20220812184215-3f9b119300de
google.golang.org/protobuf v1.28.1
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce
gopkg.in/urfave/cli.v1 v1.20.0
Expand All @@ -80,7 +80,6 @@ require (
github.com/RoaringBitmap/roaring v1.2.1 // indirect
github.com/ajwerner/btree v0.0.0-20211221152037-f427b3e689c0 // indirect
github.com/alecthomas/atomic v0.1.0-alpha2 // indirect
github.com/allegro/bigcache/v3 v3.0.3-0.20220614095342-7c2932edbec2 // indirect
github.com/anacrolix/chansync v0.3.0 // indirect
github.com/anacrolix/dht/v2 v2.19.0 // indirect
github.com/anacrolix/envpprof v1.2.1 // indirect
Expand Down Expand Up @@ -122,6 +121,8 @@ require (
github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/dgraph-io/badger/v3 v3.0.0-20220802162129-2de177900e3c // indirect
github.com/dgraph-io/ristretto v0.1.0 // indirect
github.com/dlclark/regexp2 v1.7.0 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/edsrzf/mmap-go v1.1.0 // indirect
Expand All @@ -134,6 +135,9 @@ require (
github.com/goccy/go-json v0.9.11 // indirect
github.com/gofrs/uuid v4.3.0+incompatible // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.0.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/flatbuffers v22.9.29+incompatible // indirect
github.com/google/go-cmp v0.5.9 // indirect
Expand All @@ -144,6 +148,7 @@ require (
github.com/influxdata/flux v0.184.2 // indirect
github.com/influxdata/influxql v1.1.1-0.20211004132434-7e7d61973256 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/klauspost/compress v1.15.11 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/lib/pq v1.10.6 // indirect
Expand Down Expand Up @@ -193,9 +198,12 @@ require (
github.com/tklauser/numcpus v0.5.0 // indirect
github.com/uber/jaeger-client-go v2.30.0+incompatible // indirect
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
github.com/ucwong/go-ttlmap v1.0.2-0.20220906034005-3632715c09cf // indirect
github.com/ucwong/golang-kv v1.0.10-0.20220911003714-51ffe42c65e6 // indirect
github.com/xlab/treeprint v1.1.0 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
go.etcd.io/bbolt v1.3.7-0.20220226045046-fd5535f71f48 // indirect
go.opencensus.io v0.23.0 // indirect
go.opentelemetry.io/otel v1.10.0 // indirect
go.opentelemetry.io/otel/trace v1.10.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
Expand All @@ -208,7 +216,6 @@ require (
golang.org/x/term v0.0.0-20220919170432-7a66f970e087 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.81.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.3.0 // indirect
)
Loading

0 comments on commit eda1969

Please sign in to comment.