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

Initial Refactor to Remove the Worker Abstraction #109

Merged
merged 13 commits into from
Jul 27, 2017

Conversation

chadlagore
Copy link
Contributor

@chadlagore chadlagore commented Jul 24, 2017

Status: Ready to merge.

Related Issue

106

Description

  • We've decided to 🔫 the worker abstraction.

Todos

  • Fix everything I just fucked up.

General:

  • Tests (still working)

func TestRequestHandlerNewBlockOK(t *testing.T) {
initializeChain()
a := App{PeerStore: peer.NewPeerStore("127.0.0.1:8000")}
// TODO: Enable once block request by hash implemented.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@david-julien is working on something to fix this test

@coveralls
Copy link

Coverage Status

Coverage decreased (-2.4%) to 67.798% when pulling a15a631 on 106-refactor-work-structure into d630511 on dev.

@coveralls
Copy link

Coverage Status

Coverage decreased (-2.4%) to 67.798% when pulling c5b2ab3 on 106-refactor-work-structure into d630511 on dev.

@coveralls
Copy link

Coverage Status

Coverage decreased (-2.4%) to 67.798% when pulling c5b2ab3 on 106-refactor-work-structure into d630511 on dev.

Copy link
Member

@bfbachmann bfbachmann left a comment

Choose a reason for hiding this comment

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

I like what I see Chad.. I like what I see

CurrentUser *User
PeerStore *peer.PeerStore
Chain *blockchain.BlockChain
Pool *pool.Pool
Copy link
Member

Choose a reason for hiding this comment

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

AEEE LEEETS GOOOOO!!!!

app/app.go Outdated
}

// BlockWorkQueue is a queue of blocks to process.
var blockQueue = make(chan *blockchain.Block, blockQueueSize)
Copy link
Member

Choose a reason for hiding this comment

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

I would wrap these all up like this:

var (
    blockQueue = make(chan *blockchain.Block, blockQueueSize)
    ...
)

app/app.go Outdated
@@ -110,7 +121,7 @@ func Run(cfg conf.Config) {
}
log.Info("Redirecting logs to logfile")
log.SetOutput(logFile)
go RunConsole(a.PeerStore)
go RunConsole(a.PeerStore, &a)
Copy link
Member

Choose a reason for hiding this comment

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

Might as well change RunConsole to only take the app instance as an argument since we can access the PeerStore from a.

app/app.go Outdated
// TODO: If not, request chain from peers.
// HandleTransaction handles new instance of TransactionWork.
func (a *App) HandleTransaction(txn *blockchain.Transaction) {
validTransaction := a.Pool.Set(txn, a.Chain)
Copy link
Member

Choose a reason for hiding this comment

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

Can we rename Set to Insert or Add? I feel like Set doesn't really make sense give what it actually does.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure! Push seems good to me. It goes on the back of the queue.

})
shell.AddCmd(&ishell.Cmd{
Name: "peers",
Help: "show the peers this host is connected to",
Func: peers,
Func: func(ctx *ishell.Context) {
Copy link
Member

Choose a reason for hiding this comment

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

Why wrap function calls in new anonymous functions? Couldn't you, for example, make peers take ctx and then just do the stuff peers currently does? That would make the code shorter and more readable.

Copy link
Member

Choose a reason for hiding this comment

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

I see now that you're doing it because you only have access to app from Run(), but that need not be the case in my opinion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The original situation was making app and peerStore global, which seemed less than ideal to me.

pool/pool.go Outdated
@@ -64,11 +71,13 @@ func getIndex(a []*PooledTransaction, target time.Time, low, high int) int {
// Set inserts a transaction into the pool, returning
// true if the Transaction was inserted (was valid).
func (p *Pool) Set(t *blockchain.Transaction, bc *blockchain.BlockChain) bool {
if ok, _ := bc.ValidTransaction(t); ok {
if ok, err := bc.ValidTransaction(t); ok {
p.set(t)
Copy link
Member

Choose a reason for hiding this comment

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

Will this succeed (ie add the transaction to the pool) if the transaction is valid wrt the blockchain but is not valid wrt some transaction already in the pool? ie. the input already exists in the pool. Does p.set handle that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since the transactions are mapped by input hash, this type of situation currently would overwrite the existing transaction in the pool. Thats better than letting a double spend, but its not great. I'll work on it 👍

Copy link
Member

@jordanschalm jordanschalm left a comment

Choose a reason for hiding this comment

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

Nice refactor

PeerStore: peer.NewPeerStore(addr),
PeerStore: peer.NewPeerStore(addr),
CurrentUser: getCurrentUser(),
Chain: getLocalChain(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not great. In the case when the chain is not yet local, we don't exactly want to kick off a torrenting at this exact moment. We might want the chain download to be voluntary. A CLI request 🤔

@coveralls
Copy link

Coverage Status

Coverage decreased (-2.4%) to 67.839% when pulling 815f38e on 106-refactor-work-structure into d630511 on dev.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.2%) to 69.034% when pulling 16dde33 on 106-refactor-work-structure into d630511 on dev.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.2%) to 69.034% when pulling eefcbc3 on 106-refactor-work-structure into d630511 on dev.

@chadlagore chadlagore changed the title [WIP] Initial Refactor to Remove the Worker Abstraction Initial Refactor to Remove the Worker Abstraction Jul 27, 2017
@coveralls
Copy link

Coverage Status

Coverage increased (+0.8%) to 71.036% when pulling 8e6f46b on 106-refactor-work-structure into d630511 on dev.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.8%) to 71.036% when pulling 8e6f46b on 106-refactor-work-structure into d630511 on dev.

@chadlagore chadlagore merged commit 5e0015e into dev Jul 27, 2017
@jordanschalm jordanschalm deleted the 106-refactor-work-structure branch August 30, 2017 21:10
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.

None yet

4 participants