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

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.

  • Thank you so much! will accept your answer! but could you please refer me for explannation for point 1 as i did not understand it!. for point 3, it worked but sometimes generate two or three blocks and i do not know why? is it because the ease of difficulty in generating block? Thanks again – MWH Aug 2 '17 at 16:16
  • 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: – BinGoBinBin Aug 2 '17 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 } – BinGoBinBin Aug 2 '17 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. – BinGoBinBin Aug 2 '17 at 16:41
  • do the same but cannot get the time printed on the command line, how to print the time? Thanks – MWH Aug 14 '17 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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