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

Implement basic mining logic #17

Merged
merged 5 commits into from
Jul 11, 2019
Merged

Implement basic mining logic #17

merged 5 commits into from
Jul 11, 2019

Conversation

whyrusleeping
Copy link
Member

Implemented basic block generation in-process. Starts via lotus miner start its not great, but I like that it just uses the api interface, making it really easy to replace.

I had to do a bit of a hack on the sync code to get it to work with the first person who starts the chain (doesnt have to sync the chain because they are creating it from the beginning). Some thoughts there would be nice.

@@ -20,8 +20,9 @@ type Version struct {
type API interface {
// chain

ChainHead(context.Context) ([]cid.Cid, error)
ChainHead(context.Context) (*chain.TipSet, error) // TODO: check serialization
Copy link
Member Author

Choose a reason for hiding this comment

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

it seems i broke serialization here. Need to fix

// peer heads
// Note: clear cache on disconnects
peerHeads map[peer.ID]*TipSet
peerHeadsLk sync.Mutex
}

func NewSyncer(cs *ChainStore, bsync *BlockSync) (*Syncer, error) {
func NewSyncer(cs *ChainStore, bsync *BlockSync, self peer.ID) (*Syncer, error) {
Copy link
Member Author

Choose a reason for hiding this comment

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

@magik6k does this 'self' get properly filled in with the right value? thats pretty magical.

Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -120,6 +123,21 @@ func (syncer *Syncer) InformNewHead(from peer.ID, fts *FullTipSet) {
if fts == nil {
panic("bad")
}
if from == syncer.self {
// TODO: this is kindof a hack...
Copy link
Member Author

Choose a reason for hiding this comment

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

so, the reason this is here is for the case when the node gets started, is in bootstrap sync mode, but isnt connected to anyone. Then they create a new block, while still in bootstrap sync mode, and then fail to sync it because reasons.

It really just makes me think all this sync code i wrote smells bad. Someone should rewrite it at some point soon.

@@ -171,7 +171,7 @@ func Online() Option {
Override(new(*chain.MessagePool), chain.NewMessagePool),

Override(new(modules.Genesis), testing.MakeGenesis),
Override(SetGenisisKey, modules.SetGenesis),
Override(SetGenesisKey, modules.SetGenesis),
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like you didn't push the file with this.

Answering your question from Slack - you need to wrap this into a function returning the one to invoke, like:

node/modules/core.go

func SetGenesisKey(genesis cid) func() error {
	return func() error {
		// set
	}
}

Then set in daemon/cmd.go:

api, err := node.New(ctx,
	node.Online(),
	Override(node.SetGenesisKey, modules.SetGenesis(keyFromFlag)),
)

@Kubuxu
Copy link
Contributor

Kubuxu commented Jul 11, 2019

In general SGWM.

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.

3 participants