From de32947dcf2dbce3486c0facf3f4988c9f29f887 Mon Sep 17 00:00:00 2001 From: Tim Williams Date: Thu, 21 Jun 2018 14:36:39 -0400 Subject: [PATCH] wip --- core/shyft_database_util.go | 9 +- core/shyft_tracer.go | 60 -------- eth/api.go | 2 +- eth/api_tracer.go | 183 +++++++++++++++++++++++ eth/backend.go | 5 +- eth/chaindb.go | 15 +- eth/shyft_tracer.go | 63 ++++++++ internal/jsre/jsre.go | 2 + rpc/http.go | 4 + shyfttracerinterface/tracer_interface.go | 5 + 10 files changed, 280 insertions(+), 68 deletions(-) delete mode 100644 core/shyft_tracer.go create mode 100644 eth/shyft_tracer.go create mode 100644 shyfttracerinterface/tracer_interface.go diff --git a/core/shyft_database_util.go b/core/shyft_database_util.go index 4e464d211b..2b8fe64b05 100644 --- a/core/shyft_database_util.go +++ b/core/shyft_database_util.go @@ -13,8 +13,15 @@ import ( _ "github.com/lib/pq" Rewards "github.com/ethereum/go-ethereum/consensus/ethash" + "github.com/ethereum/go-ethereum/shyfttracerinterface" ) +var IShyftTracer shyfttracerinterface.IShyftTracer + +func SetIShyftTracer(st shyfttracerinterface.IShyftTracer) { + IShyftTracer = st +} + //SBlock type type SBlock struct { Hash string @@ -165,7 +172,7 @@ func SwriteTransactions(sqldb *sql.DB, tx *types.Transaction, blockHash common.H Data: tx.Data(), } txHash := txData.TxHash.Hex() - MyTraceTransaction(txHash) //.chaindb_global + IShyftTracer.MyTraceTransaction(txHash) //.chaindb_global from := txData.From.Hex() blockHasher := txData.BlockHash amount := txData.Amount.String() diff --git a/core/shyft_tracer.go b/core/shyft_tracer.go deleted file mode 100644 index 56581b046f..0000000000 --- a/core/shyft_tracer.go +++ /dev/null @@ -1,60 +0,0 @@ -package core - -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 EthereumObject interface{} - -var Chaindb_global ethdb.Database - -func SetChainDB(db ethdb.Database){ - Chaindb_global = db -} - -func MyTraceTransaction(hash string) (interface{}) { - //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 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) - fmt.Println(index) - return 42 -} - -func setEthObject(ethobj interface{}){ - EthereumObject = ethobj -} \ No newline at end of file diff --git a/eth/api.go b/eth/api.go index d2491f7821..a345b57e49 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 8f2fd54568..81622f208e 100644 --- a/eth/api_tracer.go +++ b/eth/api_tracer.go @@ -532,6 +532,189 @@ func (api *PrivateDebugAPI) computeStateDB(block *types.Block, reexec uint64) (* // TraceTransaction returns the structured logs created during the execution of EVM // and returns them as a JSON object. func (api *PrivateDebugAPI) TraceTransaction(ctx context.Context, hash common.Hash, config *TraceConfig) (interface{}, error) { + fmt.Println("TRACE TRANSACTION ++++++!+!+!+!+!+!+!+!+!+!+!+!++!") + _, file, no, ok := runtime.Caller(1) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(2) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(3) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(4) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(5) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(6) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(7) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(8) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(9) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(10) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(11) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(12) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(13) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(14) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(15) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(16) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(17) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(18) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(19) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(20) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(21) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(22) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(23) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(24) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(25) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(26) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(27) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(28) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(29) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(30) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(31) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(32) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(33) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(34) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(35) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(36) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(37) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(38) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(39) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(40) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + fmt.Println("////////////// ++++++++++++++++ /////////////////// Phantom *(!*!*!*!*!*!**!*!*") + _, file, no, ok = runtime.Caller(41) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(42) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(43) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + _, file, no, ok = runtime.Caller(44) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } + fmt.Println("////////////// ++++++++++++++++ /////////////////// TraceTransaction *(!*!*!*!*!*!**!*!*") + _, file, no, ok = runtime.Caller(45) + if ok { + fmt.Printf("called from %s#%d\n", file, no) + } // NOTE:SHYFT 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) diff --git a/eth/backend.go b/eth/backend.go index 8e2f81bb6e..34d847bf2c 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -51,7 +51,7 @@ import ( var BlockchainObject *core.BlockChain -var DebugApi *PrivateDebugAPI +var DebugApi PrivateDebugAPI type LesServer interface { Start(srvr *p2p.Server) @@ -106,6 +106,9 @@ func (s *Ethereum) AddLesServer(ls LesServer) { // initialisation of the common Ethereum object) func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) { + shyft_tracer := new(ShyftTracer) + core.SetIShyftTracer(shyft_tracer) + fmt.Println("++++++++++") _, file, no, ok := runtime.Caller(1) if ok { diff --git a/eth/chaindb.go b/eth/chaindb.go index e17cd37771..f4ced9929b 100644 --- a/eth/chaindb.go +++ b/eth/chaindb.go @@ -4,22 +4,27 @@ import ( "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/node" "fmt" - "github.com/ethereum/go-ethereum/core" ) +var Chaindb_global ethdb.Database + +func SetChainDB(db ethdb.Database){ + Chaindb_global = db +} + func chaindb(ctx *node.ServiceContext, config *Config) (ethdb.Database, error) { fmt.Println("DO WE GET HERE ++++++++++++++++++++++++++++++++") fmt.Printf("%+v", ctx) - if core.Chaindb_global != nil { - return core.Chaindb_global, nil + if Chaindb_global != nil { + return Chaindb_global, nil } fmt.Println("FAR OUT ++++++++++++++++++++++++++++++++") chainDb, err := CreateDB(ctx, config, "chaindata") fmt.Println("CHECK CHECK ++++++++++++++++") if err == nil { - core.SetChainDB(chainDb) - return core.Chaindb_global, nil + SetChainDB(chainDb) + return Chaindb_global, nil } return nil, err } \ No newline at end of file diff --git a/eth/shyft_tracer.go b/eth/shyft_tracer.go new file mode 100644 index 0000000000..78fc206d32 --- /dev/null +++ b/eth/shyft_tracer.go @@ -0,0 +1,63 @@ +package eth + +import ( + "github.com/ethereum/go-ethereum/common" + "fmt" + "github.com/ethereum/go-ethereum/core" +) + +//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 EthereumObject interface{} + +type ShyftTracer struct {} + +func (st ShyftTracer) MyTraceTransaction(hash string) (interface{}) { + //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 in MyTraceTransaction") + //fmt.Println(Chaindb_global) + if Chaindb_global == nil { + return nil + } + + tx, blockHash, _, index := core.GetTransaction(Chaindb_global, common_hash) + + if tx == nil { + fmt.Println("TRANSACTION NOT FOUND IN MyTraceTransaction +++++++++") + } + + reexec := defaultTraceReexec + //if config != nil && config.Reexec != nil { + // reexec = *config.Reexec + //} + msg, vmctx, statedb, err := DebugApi.computeTxEnv(blockHash, int(index), reexec) + + fmt.Println("stuff and nonsense") + fmt.Println(msg) + fmt.Println(vmctx) + fmt.Println(statedb) + fmt.Println(err) + + //fmt.Println("the tx is ") + //fmt.Println(tx) + //fmt.Println(blockHash) + //fmt.Println(index) + //DebugApi.traceTx(ctx, msg, vmctx, statedb, config) + return 42 +} + +func setEthObject(ethobj interface{}){ + EthereumObject = ethobj +} \ No newline at end of file diff --git a/internal/jsre/jsre.go b/internal/jsre/jsre.go index f05865eca6..7a7ba2efc9 100644 --- a/internal/jsre/jsre.go +++ b/internal/jsre/jsre.go @@ -188,6 +188,8 @@ loop: arguments = make([]interface{}, 1) } arguments[0] = timer.call.ArgumentList[0] + fmt.Println("The arguments are") + fmt.Println(arguments) _, err := vm.Call(`Function.call.call`, nil, arguments...) if err != nil { fmt.Println("js error:", err, arguments) diff --git a/rpc/http.go b/rpc/http.go index 9805d69b63..3011222483 100644 --- a/rpc/http.go +++ b/rpc/http.go @@ -231,6 +231,10 @@ func (h *virtualHostHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } if ipAddr := net.ParseIP(host); ipAddr != nil { // It's an IP address, we can serve that + fmt.Println("THE write is ") + fmt.Println(w) + fmt.Println("The read is ") + fmt.Println(r) h.next.ServeHTTP(w, r) return diff --git a/shyfttracerinterface/tracer_interface.go b/shyfttracerinterface/tracer_interface.go new file mode 100644 index 0000000000..a2f775e570 --- /dev/null +++ b/shyfttracerinterface/tracer_interface.go @@ -0,0 +1,5 @@ +package shyfttracerinterface + +type IShyftTracer interface { + MyTraceTransaction(hash string) (interface{}) +}