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

mining: Store block templates given by notifywork. #1949

Merged
merged 1 commit into from
Oct 16, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion rpcwebsocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ func updateReasonToWorkNtfnString(reason TemplateUpdateReason) string {

// notifyWork notifies websocket clients that have registered for template
// updates when a new block template is generated.
func (*wsNotificationManager) notifyWork(clients map[chan struct{}]*wsClient, templateNtfn *TemplateNtfn) {
func (m *wsNotificationManager) notifyWork(clients map[chan struct{}]*wsClient, templateNtfn *TemplateNtfn) {
// Skip notification creation if no clients have requested work
// notifications.
if len(clients) == 0 {
Expand Down Expand Up @@ -937,6 +937,15 @@ func (*wsNotificationManager) notifyWork(clients map[chan struct{}]*wsClient, te
return
}

// Add the template to the template pool. Since the key is a combination
// of the merkle and stake root fields, this will not add duplicate entries
// for the templates with modified timestamps and/or difficulty bits.
templateKey := getWorkTemplateKey(header)
state := m.server.workState
state.Lock()
state.templatePool[templateKey] = templateNtfn.Template.Block
state.Unlock()

for _, wsc := range clients {
wsc.QueueNotification(marshalledJSON)
}
Expand Down