diff --git a/core/blockchain.go b/core/blockchain.go index 4216999069..f40f6019e7 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -28,7 +28,8 @@ import ( "sync" "sync/atomic" "time" - + + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/mclock" "github.com/ethereum/go-ethereum/consensus" @@ -45,6 +46,7 @@ import ( "github.com/ethereum/go-ethereum/trie" "github.com/hashicorp/golang-lru" "gopkg.in/karalabe/cookiejar.v2/collections/prque" + "runtime" ) var ( @@ -900,16 +902,13 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types. if err := WriteBlock(batch, block); err != nil { return NonStatTy, err } - // NOTE:SHYFT - Write block data for block explorer - fmt.Printf("\n\t[BLOCKCHAIN.GO bc.chainConfig] %+v", bc.chainConfig) - if err := SWriteBlock(block, receipts); err != nil { - return NonStatTy, err - } root, err := state.Commit(bc.chainConfig.IsEIP158(block.Number())) + if err != nil { return NonStatTy, err } + triedb := bc.stateCache.TrieDB() // If we're running an archive node, always flush @@ -1001,6 +1000,12 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types. if status == CanonStatTy { bc.insert(block) } + + // NOTE:SHYFT - Write block data for block explorer + fmt.Printf("\n\t[BLOCKCHAIN.GO bc.chainConfig] %+v", bc.chainConfig) + if err := SWriteBlock(block, receipts); err != nil { + return NonStatTy, err + } bc.futureBlocks.Remove(block.Hash()) return status, nil } @@ -1021,6 +1026,11 @@ func (bc *BlockChain) InsertChain(chain types.Blocks) (int, error) { // only reason this method exists as a separate one is to make locking cleaner // with deferred statements. func (bc *BlockChain) insertChain(chain types.Blocks) (int, []interface{}, []*types.Log, error) { + fmt.Println("++++++++++ insertChain +++++++++") + _, file, no, ok := runtime.Caller(1) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } // Do a sanity check that the provided chain is actually ordered and linked for i := 1; i < len(chain); i++ { if chain[i].NumberU64() != chain[i-1].NumberU64()+1 || chain[i].ParentHash() != chain[i-1].Hash() { diff --git a/core/database_util.go b/core/database_util.go index 37f0daf952..8aabd94034 100644 --- a/core/database_util.go +++ b/core/database_util.go @@ -266,7 +266,14 @@ func GetBlockReceipts(db DatabaseReader, hash common.Hash, number uint64) types. // hash to allow retrieving the transaction or receipt by hash. func GetTxLookupEntry(db DatabaseReader, hash common.Hash) (common.Hash, uint64, uint64) { // Load the positional metadata from disk and bail if it fails + fmt.Println("INSIDE GetTxLookupEntry ") + fmt.Println("the db is ") + fmt.Println(db) + fmt.Println("the hash is") + fmt.Println(hash) data, _ := db.Get(append(lookupPrefix, hash.Bytes()...)) + fmt.Println("the data is ") + fmt.Println(data) if len(data) == 0 { return common.Hash{}, 0, 0 } @@ -283,7 +290,13 @@ func GetTxLookupEntry(db DatabaseReader, hash common.Hash) (common.Hash, uint64, // its added positional metadata. func GetTransaction(db DatabaseReader, hash common.Hash) (*types.Transaction, common.Hash, uint64, uint64) { // Retrieve the lookup metadata and resolve the transaction from the body + //fmt.Println("INSIDE GET TRANSACTION ++++++++") + //fmt.Println("The hash and db reader are") + //fmt.Println(hash) + //fmt.Println(db) blockHash, blockNumber, txIndex := GetTxLookupEntry(db, hash) + //fmt.Println(blockHash) + //fmt.Println(blockNumber) if blockHash != (common.Hash{}) { body := GetBody(db, blockHash, blockNumber) diff --git a/core/shyft_tracer.go b/core/shyft_tracer.go index aac6bf5db6..391ada4257 100644 --- a/core/shyft_tracer.go +++ b/core/shyft_tracer.go @@ -4,29 +4,49 @@ import ( "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/common" "fmt" + ) +const ( + // defaultTraceReexec is the number of blocks the tracer is willing to go back + // and reexecute to produce missing historical state necessary to run a specific + // trace. + defaultTraceReexec = uint64(128) +) + +//var api *eth.PrivateDebugAPI + var Chaindb_global ethdb.Database func SetChainDB(db ethdb.Database){ Chaindb_global = db } - - func MyTraceTransaction(hash string) (interface{}) { - common_hash := common.StringToHash(hash) - fmt.Println("the hash is") - fmt.Println(common_hash) + //fmt.Println("THE stringed hash is in MYTRACETRANSACTION") + //fmt.Println(hash) + //fmt.Println(ethObjectInterface.GetEthObject()) + common_hash := common.HexToHash(hash) - fmt.Println("the chain db is") - fmt.Println(Chaindb_global) + + //fmt.Println("the chain db is in MyTraceTransaction") + //fmt.Println(Chaindb_global) if Chaindb_global == nil { return nil } tx, blockHash, _, index := GetTransaction(Chaindb_global, common_hash) + //reexec := defaultTraceReexec + //if config != nil && config.Reexec != nil { + // reexec = *config.Reexec + //} + //msg, vmctx, statedb, err := eth.api.computeTxEnv(blockHash, int(index), reexec) + + if tx == nil { + fmt.Println("TRANSACTION NOT FOUND IN MyTraceTransaction +++++++++") + } + fmt.Println("the tx is ") fmt.Println(tx) fmt.Println(blockHash) diff --git a/eth/api.go b/eth/api.go index a345b57e49..d2491f7821 100644 --- a/eth/api.go +++ b/eth/api.go @@ -330,7 +330,7 @@ func (api *PublicDebugAPI) DumpBlock(blockNr rpc.BlockNumber) (state.Dump, error // PrivateDebugAPI is the collection of Ethereum full node APIs exposed over // the private debugging endpoint. -type PrivateDebugAPI struct { +type PrivateDebugAPI struct { config *params.ChainConfig eth *Ethereum } diff --git a/eth/api_tracer.go b/eth/api_tracer.go index fa6af256ad..8f2fd54568 100644 --- a/eth/api_tracer.go +++ b/eth/api_tracer.go @@ -536,10 +536,19 @@ func (api *PrivateDebugAPI) TraceTransaction(ctx context.Context, hash common.Ha fmt.Printf("\n\t[API_TRACER.GO api.config] %+v", api.config) fmt.Printf("\n\t[API_TRACER.GO api.eth] %+v\n", api.eth) // Retrieve the transaction and assemble its EVM context + //fmt.Println("IN TRACE TRANSACTION the chaindb is ") + //fmt.Println(chaindb) + //fmt.Println("IN TRACE TRANSACTION the common hash is ") + //fmt.Println(hash) tx, blockHash, _, index := core.GetTransaction(api.eth.ChainDb(), hash) if tx == nil { return nil, fmt.Errorf("transaction %x not found", hash) } + + fmt.Println("the tx is in TraceTransaction") + fmt.Println(tx) + fmt.Println(blockHash) + fmt.Println(index) reexec := defaultTraceReexec if config != nil && config.Reexec != nil { reexec = *config.Reexec diff --git a/eth/backend.go b/eth/backend.go index c78cfa3164..a3fd81d662 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -49,6 +49,10 @@ import ( "github.com/ethereum/go-ethereum/rpc" ) +var EthObject *Ethereum + +var BlockchainObject *core.BlockChain + type LesServer interface { Start(srvr *p2p.Server) Stop() @@ -101,6 +105,13 @@ func (s *Ethereum) AddLesServer(ls LesServer) { // New creates a new Ethereum object (including the // initialisation of the common Ethereum object) func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) { + + fmt.Println("++++++++++") + _, file, no, ok := runtime.Caller(1) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + if config.SyncMode == downloader.LightSync { return nil, errors.New("can't run eth.Ethereum in light sync mode, use les.LightEthereum") } @@ -137,6 +148,8 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) { bloomIndexer: NewBloomIndexer(chainDb, params.BloomBitsBlocks), } + EthObject = eth + log.Info("Initialising Ethereum protocol", "versions", ProtocolVersions, "network", config.NetworkId) if !config.SkipBcVersionCheck { @@ -150,7 +163,11 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) { vmConfig = vm.Config{EnablePreimageRecording: config.EnablePreimageRecording} cacheConfig = &core.CacheConfig{Disabled: config.NoPruning, TrieNodeLimit: config.TrieCache, TrieTimeLimit: config.TrieTimeout} ) + eth.blockchain, err = core.NewBlockChain(chainDb, cacheConfig, eth.chainConfig, eth.engine, vmConfig) + + BlockchainObject = eth.blockchain + if err != nil { return nil, err } diff --git a/ethObjectInterface/eth_object.go b/ethObjectInterface/eth_object.go new file mode 100644 index 0000000000..5e999762d3 --- /dev/null +++ b/ethObjectInterface/eth_object.go @@ -0,0 +1,9 @@ +package ethObjectInterface + +import "github.com/ethereum/go-ethereum/eth" + +//var ethObject *eth.Ethereum + +func GetEthObject() (interface{}){ + return eth.EthObject +} \ No newline at end of file