0

I am using private network with geth 1.7, and have some questions

1- To get the time of executing a function, i found some discussion about use of Data.getTime(), but i am wondering if anyone was successfully able to implement other methods such as performance.now() to measure time in geth commandlines? I tried but seems not defined function!!

2- how can i get the timestamp for a specific block if i knew the block number?

3- how can i mine only one block. For example, i send one transaction to the private network and then only mine one block containing that transaction. I found here some suggest to use while loop to check if there is no pending transactions and then stop mining. But i do not want this method, i would rather prefer to only mine one block.

Thanks in advance,

1 Answer 1

1

1:You could get the time of executing a function by updating source on jsre.go file,as follows:

func (self *JSRE) Evaluate(code string, w io.Writer) error {
    var fail error

    self.Do(func(vm *otto.Otto) {
        var startTime = time.Now();
        fmt.Println("jsre function ",code," start")
        val, err := vm.Run(code)
        if err != nil {
            prettyError(vm, err, w)
        } else {
            prettyPrint(vm, val, w)
        }
        fmt.Fprintln(w)
        fmt.Println("jsre function ",code," end ,consume time " ,(time.Now().UnixNano() - startTime.UnixNano()))
    })
    return fail
}

and then, deploy contract to test.

2: there is no way to obtain block timestamp by number, block.timestamp or now just is current block timestamp as seconds since unix epoch.

3:miner.start(1);admin.sleepBlocks(1);miner.stop(); just mines one block and then will stop mine. Please notice executing by together.

6
  • Maybe difficulty too low generating two or three for point 3,this phenomenon require ayalysis source. For point 1, you will update and compile source. 1. clone go-ethereum 2. find method Evaluate in jsre.go file and replace Evaluate as follow: Commented Aug 2, 2017 at 16:40
  • func (self *JSRE) Evaluate(code string, w io.Writer) error { var fail error self.Do(func(vm *otto.Otto) { var startTime = time.Now(); fmt.Println("jsre function ",code," start") val, err := vm.Run(code) if err != nil { prettyError(vm, err, w) } else { prettyPrint(vm, val, w) } fmt.Fprintln(w) fmt.Println("jsre function ",code," end ,consume time " ,(time.Now().UnixNano() - startTime.UnixNano())) }) return fail } Commented Aug 2, 2017 at 16:40
  • 3. cd go-ethereum dir on terminal and execute make all. 4. start geth. './build/bin/geth --datadir=./dev/data --networkid 1 --dev console' 5. deploy your contract and test. Commented Aug 2, 2017 at 16:41
  • do the same but cannot get the time printed on the command line, how to print the time? Thanks
    – MWH
    Commented Aug 14, 2017 at 14:19
  • did you modify source and execute 'make all' to rebuild geth, and start geth by ./build/bin/geth --datadir=./dev/data --networkid 1 --dev console? this way is ok for me, please every step is correct~ Commented Aug 14, 2017 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.