Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

console: admin.clearHistory() command #15614

Merged
merged 5 commits into from
Dec 8, 2017

Conversation

sorin
Copy link
Contributor

@sorin sorin commented Dec 6, 2017

No description provided.

@holiman
Copy link
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 ?

@@ -216,6 +217,12 @@ func (c *Console) init(preload []string) error {
return nil
}

func (c *Console) clearHistory() {
c.history = nil
c.prompter.ClearHistory()
Copy link
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
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
Contributor Author

sorin commented Dec 7, 2017

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

@@ -51,6 +51,9 @@ type UserPrompter interface {
// if and only if the prompt to append was a valid command.
AppendHistory(command string)

// ClearHistory clears the entire history
ClearHistory()
Copy link
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
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

@@ -216,6 +217,13 @@ func (c *Console) init(preload []string) error {
return nil
}

func (c *Console) clearHistory() {
Copy link
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

func (c *Console) clearHistory() {
c.history = nil
c.prompter.ClearHistory()
os.Remove(c.histPath)
Copy link
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)

c.history = nil
c.prompter.ClearHistory()
os.Remove(c.histPath)
fmt.Fprintf(c.printer, "history cleared\n")
Copy link
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
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
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
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