Skip to content

console: admin.clearHistory() command#15614

Merged
fjl merged 5 commits into
ethereum:masterfrom
sorin:sorin-console-clear-history
Dec 8, 2017
Merged

console: admin.clearHistory() command#15614
fjl merged 5 commits into
ethereum:masterfrom
sorin:sorin-console-clear-history

Conversation

@sorin
Copy link
Copy Markdown
Contributor

@sorin sorin commented Dec 6, 2017

No description provided.

@holiman
Copy link
Copy Markdown
Contributor

holiman commented Dec 6, 2017

I have not tested this, but based manual look at the code, I wonder if it actually deletes the history-file from disk ?

Comment thread console/console.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please call os.Remove(c.histPath) here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. my original reasoning was that history is being persisted at the end of the session but I agree this is safer.

@sorin sorin force-pushed the sorin-console-clear-history branch from 0650063 to 271a978 Compare December 6, 2017 15:26
@sorin
Copy link
Copy Markdown
Contributor Author

sorin commented Dec 7, 2017

@fjl added a one liner test fix, please approve. thanks!

Comment thread console/prompter.go
AppendHistory(command string)

// ClearHistory clears the entire history
ClearHistory()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest ClearHistory() error, now that the os.remove may return an error

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good suggestion, but since https://github.com/sorin/go-ethereum/blob/sorin-console-clear-history/vendor/github.com/peterh/liner/common.go#L148-L152 does not return an error I'd say ClearHistory() (which is basically a wrapper on top of it) stays like this. Also os.remove is not called inside this ClearHistory() - I did add an error return to Console.clearHistory

Comment thread console/console.go
return nil
}

func (c *Console) clearHistory() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to let this return an error

Comment thread console/console.go Outdated
func (c *Console) clearHistory() {
c.history = nil
c.prompter.ClearHistory()
os.Remove(c.histPath)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... and do return os.Remove(c.histPath)

Comment thread console/console.go Outdated
c.history = nil
c.prompter.ClearHistory()
os.Remove(c.histPath)
fmt.Fprintf(c.printer, "history cleared\n")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is needed.. @fjl ?

@sorin
Copy link
Copy Markdown
Contributor Author

sorin commented Dec 7, 2017

@holiman @fjl take another look please, made Console.clearHistory return an error and removed the text out confirmation. Another option would be to have clearHistory return bool, err to keep it consistent with https://github.com/sorin/go-ethereum/blob/sorin-console-clear-history/node/api.go#L63-L76

@holiman
Copy link
Copy Markdown
Contributor

holiman commented Dec 8, 2017

Hm.. I was just about to press 'approve' on this, but then I decided to test it, and found two snags...

When running geth as I do, geth --config prod.config, and have the datadir set to something non-standard, e.g./media/datadisk/eth_datadir/.. And later, when I do a geth attach /media/datadisk/eth_datadir/geth.ipc, the history is saved as ~/.ethereum/history, since geth attach instance is not using the same datadir, just the same ipc.

This is a problem with the current code, not a new problem in this PR. To fix this, we really should have the ability to run geth --config prod.config attach , and have the second instance use the same datadir.

Another problem is if you call the clearHistory twice, or the file simply doesn't exist :

undefined
> 
> 
> admin.clearHistory()
panic: Object.getOwnPropertyNames returned unexpected type <nil>

goroutine 13 [running]:
github.com/ethereum/go-ethereum/internal/jsre.iterOwnKeys(0xc4202a7c60, 0xc420e503e0, 0xc420e95578)
	/home/martin/go/src/github.com/ethereum/go-ethereum/build/_workspace/src/github.com/ethereum/go-ethereum/internal/jsre/pretty.go:239 +0x372
github.com/ethereum/go-ethereum/internal/jsre.iterOwnAndConstructorKeys(0xc4202a7c60, 0xc420e503e0, 0xc420e956f0)
	/home/martin/go/src/github.com/ethereum/go-ethereum/build/_workspace/src/github.com/ethereum/go-ethereum/internal/jsre/pretty.go:212 +0xfc
github.com/ethereum/go-ethereum/internal/jsre.ppctx.fields(0xc4202a7c60, 0x1851320, 0xc42000e018, 0xc420e503e0, 0x0, 0xa7b8bd, 0xc42026b760)
	/home/martin/go/src/github.com/ethereum/go-ethereum/build/_workspace/src/github.com/ethereum/go-ethereum/internal/jsre/pretty.go:204 +0x190
github.com/ethereum/go-ethereum/internal/jsre.ppctx.printObject(0xc4202a7c60, 0x1851320, 0xc42000e018, 0xc420e503e0, 0x0, 0xc420e95b00)
	/home/martin/go/src/github.com/ethereum/go-ethereum/build/_workspace/src/github.com/ethereum/go-ethereum/internal/jsre/pretty.go:141 +0x992
github.com/ethereum/go-ethereum/internal/jsre.ppctx.printValue(0xc4202a7c60, 0x1851320, 0xc42000e018, 0x5, 0xf266c0, 0xc420e263c0, 0x0, 0x0)
	/home/martin/go/src/github.com/ethereum/go-ethereum/build/_workspace/src/github.com/ethereum/go-ethereum/internal/jsre/pretty.go:88 +0x8d5
github.com/ethereum/go-ethereum/internal/jsre.prettyPrint(0xc4202a7c60, 0x5, 0xf266c0, 0xc420e263c0, 0x1851320, 0xc42000e018)
	/home/martin/go/src/github.com/ethereum/go-ethereum/build/_workspace/src/github.com/ethereum/go-ethereum/internal/jsre/pretty.go:56 +0x6b
github.com/ethereum/go-ethereum/internal/jsre.(*JSRE).Evaluate.func1(0xc4202a7c60)
	/home/martin/go/src/github.com/ethereum/go-ethereum/build/_workspace/src/github.com/ethereum/go-ethereum/internal/jsre/jsre.go:316 +0x154
github.com/ethereum/go-ethereum/internal/jsre.(*JSRE).runEventLoop(0xc42029f6c0)
	/home/martin/go/src/github.com/ethereum/go-ethereum/build/_workspace/src/github.com/ethereum/go-ethereum/internal/jsre/jsre.go:207 +0x69d
created by github.com/ethereum/go-ethereum/internal/jsre.New
	/home/martin/go/src/github.com/ethereum/go-ethereum/build/_workspace/src/github.com/ethereum/go-ethereum/internal/jsre/jsre.go:78 +0x145

@fjl
Copy link
Copy Markdown
Contributor

fjl commented Dec 8, 2017

clearHistory is called from JS and cannot return error. It could return a JS object, but that's not really what you want. The fix I've pushed now prints an error message if there is a problem deleting the file. I will merge this as soon as CI turns green.

@fjl fjl merged commit 586198c into ethereum:master Dec 8, 2017
@karalabe karalabe added this to the 1.8.0 milestone Dec 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants