From 03cc5df9b7ea7d9bf5569b5b4e320c7c7d0e0930 Mon Sep 17 00:00:00 2001 From: zelig Date: Mon, 23 Mar 2015 16:23:06 +0000 Subject: [PATCH 1/6] eth: fix protocol version/network id copied from config to Ethereum field --- eth/backend.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/eth/backend.go b/eth/backend.go index 06c3cbd177..4e60e16f24 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -177,15 +177,16 @@ func New(config *Config) (*Ethereum, error) { servlogger.Infof("Protocol Version: %v, Network Id: %v", config.ProtocolVersion, config.NetworkId) eth := &Ethereum{ - shutdownChan: make(chan bool), - blockDb: blockDb, - stateDb: stateDb, - extraDb: extraDb, - eventMux: &event.TypeMux{}, - // logger: servlogsystem, - accountManager: config.AccountManager, - DataDir: config.DataDir, - version: config.Name, // TODO should separate from Name + shutdownChan: make(chan bool), + blockDb: blockDb, + stateDb: stateDb, + extraDb: extraDb, + eventMux: &event.TypeMux{}, + accountManager: config.AccountManager, + DataDir: config.DataDir, + version: config.Name, // TODO should separate from Name + ProtocolVersion: config.ProtocolVersion, + NetworkId: config.NetworkId, } eth.chainManager = core.NewChainManager(blockDb, stateDb, eth.EventMux()) From 1e61b75cbf0830a72b40d0eed8f924cb7bb61aa3 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Mon, 23 Mar 2015 17:33:01 +0100 Subject: [PATCH 2/6] tests + fixes --- rpc/args.go | 9 ++++----- rpc/args_test.go | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/rpc/args.go b/rpc/args.go index 6e02b65ef3..5b655024ca 100644 --- a/rpc/args.go +++ b/rpc/args.go @@ -467,7 +467,7 @@ func (args *BlockFilterArgs) UnmarshalJSON(b []byte) (err error) { switch fromstr { case "latest": - args.Earliest = 0 + args.Earliest = -1 default: args.Earliest = int64(common.Big(obj[0].FromBlock.(string)).Int64()) } @@ -479,9 +479,9 @@ func (args *BlockFilterArgs) UnmarshalJSON(b []byte) (err error) { switch tostr { case "latest": - args.Latest = 0 - case "pending": args.Latest = -1 + case "pending": + args.Latest = -2 default: args.Latest = int64(common.Big(obj[0].ToBlock.(string)).Int64()) } @@ -775,8 +775,7 @@ func (args *SubmitWorkArgs) UnmarshalJSON(b []byte) (err error) { return NewDecodeParamError("Nonce is not a string") } - args.Nonce = common.BytesToNumber(common.Hex2Bytes(objstr)) - + args.Nonce = common.String2Big(objstr).Uint64() if objstr, ok = obj[1].(string); !ok { return NewDecodeParamError("Header is not a string") } diff --git a/rpc/args_test.go b/rpc/args_test.go index 2ad53fba2a..5cbafd4b2f 100644 --- a/rpc/args_test.go +++ b/rpc/args_test.go @@ -5,6 +5,8 @@ import ( "encoding/json" "math/big" "testing" + + "github.com/ethereum/go-ethereum/common" ) func TestSha3(t *testing.T) { @@ -440,8 +442,8 @@ func TestBlockFilterArgsWords(t *testing.T) { "toBlock": "pending" }]` expected := new(BlockFilterArgs) - expected.Earliest = 0 - expected.Latest = -1 + expected.Earliest = -1 + expected.Latest = -2 args := new(BlockFilterArgs) if err := json.Unmarshal([]byte(input), &args); err != nil { @@ -651,6 +653,10 @@ func TestFilterStringArgs(t *testing.T) { t.Error(err) } + if err := args.requirements(); err != nil { + t.Error(err) + } + if expected.Word != args.Word { t.Errorf("Word shoud be %#v but is %#v", expected.Word, args.Word) } @@ -720,3 +726,28 @@ func TestHashIndexArgs(t *testing.T) { t.Errorf("Index shoud be %#v but is %#v", expected.Index, args.Index) } } + +func TestSubmitWorkArgs(t *testing.T) { + input := `["0x0000000000000001", "0x1234567890abcdef1234567890abcdef", "0xD1GE5700000000000000000000000000"]` + expected := new(SubmitWorkArgs) + expected.Nonce = 1 + expected.Header = common.HexToHash("0x1234567890abcdef1234567890abcdef") + expected.Digest = common.HexToHash("0xD1GE5700000000000000000000000000") + + args := new(SubmitWorkArgs) + if err := json.Unmarshal([]byte(input), &args); err != nil { + t.Error(err) + } + + if expected.Nonce != args.Nonce { + t.Errorf("Nonce shoud be %d but is %d", expected.Nonce, args.Nonce) + } + + if expected.Header != args.Header { + t.Errorf("Header shoud be %#v but is %#v", expected.Header, args.Header) + } + + if expected.Digest != args.Digest { + t.Errorf("Digest shoud be %#v but is %#v", expected.Digest, args.Digest) + } +} From 9880f99ccb81477f1026db68c123aa548297c648 Mon Sep 17 00:00:00 2001 From: zelig Date: Mon, 23 Mar 2015 16:41:41 +0000 Subject: [PATCH 3/6] fix p2p/testlog_test --- p2p/testlog_test.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/p2p/testlog_test.go b/p2p/testlog_test.go index c524c154c4..ac973bcf5e 100644 --- a/p2p/testlog_test.go +++ b/p2p/testlog_test.go @@ -15,11 +15,8 @@ func testlog(t *testing.T) testLogger { return l } -func (testLogger) GetLogLevel() logger.LogLevel { return logger.DebugDetailLevel } -func (testLogger) SetLogLevel(logger.LogLevel) {} - -func (l testLogger) LogPrint(level logger.LogLevel, msg string) { - l.t.Logf("%s", msg) +func (l testLogger) LogPrint(msg logger.LogMsg) { + l.t.Logf("%s", msg.String()) } func (testLogger) detach() { From 1cf6ca8f10ab7dd5de29caf0d255c93cdec96994 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Mon, 23 Mar 2015 17:41:50 +0100 Subject: [PATCH 4/6] Add Close() method to EthereumApi To close the handler for LDB --- cmd/ethereum/js.go | 1 + rpc/api.go | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/cmd/ethereum/js.go b/cmd/ethereum/js.go index 88d16d6a82..6f0ac526f2 100644 --- a/cmd/ethereum/js.go +++ b/cmd/ethereum/js.go @@ -91,6 +91,7 @@ func newJSRE(ethereum *eth.Ethereum, libPath string) *jsre { func (js *jsre) apiBindings() { ethApi := rpc.NewEthereumApi(js.xeth, js.ethereum.DataDir) + ethApi.Close() //js.re.Bind("jeth", rpc.NewJeth(ethApi, js.re.ToVal)) jeth := rpc.NewJeth(ethApi, js.re.ToVal, js.re) diff --git a/rpc/api.go b/rpc/api.go index 4cd88aa718..19bd9b7079 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -44,6 +44,10 @@ func (api *EthereumApi) xethAtStateNum(num int64) *xeth.XEth { return api.xeth().AtStateNum(num) } +func (api *EthereumApi) Close() { + api.db.Close() +} + func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error { // Spec at https://github.com/ethereum/wiki/wiki/Generic-JSON-RPC rpclogger.Debugf("%s %s", req.Method, req.Params) From e954c24af02802cdee0870230b6dcfc898dd07cd Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Mon, 23 Mar 2015 18:06:05 +0100 Subject: [PATCH 5/6] Implement RPC net_version --- eth/backend.go | 12 +++++++----- rpc/api.go | 2 +- xeth/xeth.go | 4 +++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/eth/backend.go b/eth/backend.go index ded3f0021d..446f065310 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -13,6 +13,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/event" @@ -21,7 +22,6 @@ import ( "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p/discover" "github.com/ethereum/go-ethereum/p2p/nat" - "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/whisper" ) @@ -141,8 +141,8 @@ type Ethereum struct { Mining bool DataDir string version string - ProtocolVersion int - NetworkId int + protocolVersion int + networkId int } func New(config *Config) (*Ethereum, error) { @@ -185,8 +185,8 @@ func New(config *Config) (*Ethereum, error) { accountManager: config.AccountManager, DataDir: config.DataDir, version: config.Name, // TODO should separate from Name - ProtocolVersion: config.ProtocolVersion, - NetworkId: config.NetworkId, + protocolVersion: config.ProtocolVersion, + networkId: config.NetworkId, } eth.chainManager = core.NewChainManager(blockDb, stateDb, eth.EventMux()) @@ -325,6 +325,8 @@ func (s *Ethereum) PeerCount() int { return s.net.PeerCoun func (s *Ethereum) Peers() []*p2p.Peer { return s.net.Peers() } func (s *Ethereum) MaxPeers() int { return s.net.MaxPeers } func (s *Ethereum) Version() string { return s.version } +func (s *Ethereum) ProtocolVersion() int { return s.protocolVersion } +func (s *Ethereum) NetworkId() int { return s.networkId } // Start the ethereum func (s *Ethereum) Start() error { diff --git a/rpc/api.go b/rpc/api.go index 19bd9b7079..4bc1991765 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -62,7 +62,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err case "web3_clientVersion": *reply = api.xeth().Backend().Version() case "net_version": - return NewNotImplementedError(req.Method) + *reply = string(api.xeth().Backend().ProtocolVersion()) case "net_listening": *reply = api.xeth().IsListening() case "net_peerCount": diff --git a/xeth/xeth.go b/xeth/xeth.go index 02a691ffb9..98f5f5b36c 100644 --- a/xeth/xeth.go +++ b/xeth/xeth.go @@ -12,6 +12,7 @@ import ( "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/event" @@ -19,7 +20,6 @@ import ( "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/miner" "github.com/ethereum/go-ethereum/p2p" - "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/whisper" ) @@ -50,6 +50,8 @@ type Backend interface { StartMining() error StopMining() Version() string + ProtocolVersion() int + NetworkId() int } // Frontend should be implemented by users of XEth. Its methods are From a983a215dc50240615cc1efe5199c72cefe037ed Mon Sep 17 00:00:00 2001 From: zelig Date: Mon, 23 Mar 2015 17:08:49 +0000 Subject: [PATCH 6/6] fix ethtest logging --- cmd/ethtest/main.go | 9 ++++----- logger/logsystem.go | 12 ++++++------ tests/helper/init.go | 2 +- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/cmd/ethtest/main.go b/cmd/ethtest/main.go index f5b423e8d1..952ba1bd62 100644 --- a/cmd/ethtest/main.go +++ b/cmd/ethtest/main.go @@ -33,12 +33,12 @@ import ( "strings" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/logger" - "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/tests/helper" - "github.com/ethereum/go-ethereum/core/vm" ) type Log struct { @@ -80,8 +80,7 @@ func StateObjectFromAccount(db common.Database, addr string, account Account) *s } type VmTest struct { - Callcreates interface{} - //Env map[string]string + Callcreates interface{} Env Env Exec map[string]string Transaction map[string]string @@ -219,7 +218,7 @@ func RunVmTest(r io.Reader) (failed int) { } func main() { - //helper.Logger.SetLogLevel(5) + helper.Logger.SetLogLevel(5) vm.Debug = true if len(os.Args) > 1 { diff --git a/logger/logsystem.go b/logger/logsystem.go index 995cf42404..4dadb126e6 100644 --- a/logger/logsystem.go +++ b/logger/logsystem.go @@ -14,17 +14,17 @@ type LogSystem interface { // NewStdLogSystem creates a LogSystem that prints to the given writer. // The flag values are defined package log. -func NewStdLogSystem(writer io.Writer, flags int, level LogLevel) LogSystem { +func NewStdLogSystem(writer io.Writer, flags int, level LogLevel) *StdLogSystem { logger := log.New(writer, "", flags) - return &stdLogSystem{logger, uint32(level)} + return &StdLogSystem{logger, uint32(level)} } -type stdLogSystem struct { +type StdLogSystem struct { logger *log.Logger level uint32 } -func (t *stdLogSystem) LogPrint(msg LogMsg) { +func (t *StdLogSystem) LogPrint(msg LogMsg) { stdmsg, ok := msg.(stdMsg) if ok { if t.GetLogLevel() >= stdmsg.Level() { @@ -33,11 +33,11 @@ func (t *stdLogSystem) LogPrint(msg LogMsg) { } } -func (t *stdLogSystem) SetLogLevel(i LogLevel) { +func (t *StdLogSystem) SetLogLevel(i LogLevel) { atomic.StoreUint32(&t.level, uint32(i)) } -func (t *stdLogSystem) GetLogLevel() LogLevel { +func (t *StdLogSystem) GetLogLevel() LogLevel { return LogLevel(atomic.LoadUint32(&t.level)) } diff --git a/tests/helper/init.go b/tests/helper/init.go index e0892d8f69..73d563e021 100644 --- a/tests/helper/init.go +++ b/tests/helper/init.go @@ -7,7 +7,7 @@ import ( logpkg "github.com/ethereum/go-ethereum/logger" ) -var Logger logpkg.LogSystem +var Logger *logpkg.StdLogSystem var Log = logpkg.NewLogger("TEST") func init() {