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

fix: pass WorkObject through to SubscribeNewHeads #39

Closed
Closed
Show file tree
Hide file tree
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
27 changes: 13 additions & 14 deletions core/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,20 +447,19 @@ func (sl *Slice) Append(header *types.WorkObject, domPendingHeader *types.WorkOb
}).Info("Times during sub append")

sl.logger.WithFields(log.Fields{
"dom number": block.Header().NumberArray(),
"zone number": block.Number(common.ZONE_CTX),
"hash": block.Hash(),
"difficulty": block.Difficulty(),
"uncles": len(block.Uncles()),
"txs": len(block.Transactions()),
"etxs": len(block.ExtTransactions()),
"utxos": len(block.QiTransactions()),
"gas": block.GasUsed(),
"gasLimit": block.GasLimit(),
"evmRoot": block.EVMRoot(),
"order": order,
"location": block.Location(),
"elapsed": common.PrettyDuration(time.Since(start)),
"number": block.NumberArray(),
"hash": block.Hash(),
"difficulty": block.Difficulty(),
"uncles": len(block.Uncles()),
"txs": len(block.Transactions()),
"etxs": len(block.ExtTransactions()),
"utxos": len(block.QiTransactions()),
"gas": block.GasUsed(),
"gasLimit": block.GasLimit(),
"evmRoot": block.EVMRoot(),
"order": order,
"location": block.Location(),
"elapsed": common.PrettyDuration(time.Since(start)),
}).Info("Appended new block")

if nodeCtx == common.ZONE_CTX {
Expand Down
6 changes: 3 additions & 3 deletions quai/filters/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (api *PublicFilterAPI) NewPendingTransactions(ctx context.Context) (*rpc.Su
// https://eth.wiki/json-rpc/API#eth_newblockfilter
func (api *PublicFilterAPI) NewBlockFilter() rpc.ID {
var (
headers = make(chan *types.Header)
headers = make(chan *types.WorkObject)
headerSub = api.events.SubscribeNewHeads(headers)
)

Expand Down Expand Up @@ -266,14 +266,14 @@ func (api *PublicFilterAPI) NewHeads(ctx context.Context) (*rpc.Subscription, er
}).Fatal("Go-Quai Panicked")
}
}()
headers := make(chan *types.Header)
headers := make(chan *types.WorkObject)
headersSub := api.events.SubscribeNewHeads(headers)

for {
select {
case h := <-headers:
// Marshal the header data
marshalHeader := h.RPCMarshalHeader()
marshalHeader := h.RPCMarshalWorkObject()
notifier.Notify(rpcSub.ID, marshalHeader)
case <-rpcSub.Err():
headersSub.Unsubscribe()
Expand Down
16 changes: 8 additions & 8 deletions quai/filters/filter_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ type subscription struct {
logsCrit quai.FilterQuery
logs chan []*types.Log
hashes chan []common.Hash
headers chan *types.Header
header chan *types.Header
headers chan *types.WorkObject
header chan *types.WorkObject
installed chan struct{} // closed when the filter is installed
err chan error // closed when the filter is uninstalled
}
Expand Down Expand Up @@ -241,7 +241,7 @@ func (es *EventSystem) subscribeMinedPendingLogs(crit quai.FilterQuery, logs cha
created: time.Now(),
logs: logs,
hashes: make(chan []common.Hash),
headers: make(chan *types.Header),
headers: make(chan *types.WorkObject),
installed: make(chan struct{}),
err: make(chan error),
}
Expand All @@ -258,7 +258,7 @@ func (es *EventSystem) subscribeLogs(crit quai.FilterQuery, logs chan []*types.L
created: time.Now(),
logs: logs,
hashes: make(chan []common.Hash),
headers: make(chan *types.Header),
headers: make(chan *types.WorkObject),
installed: make(chan struct{}),
err: make(chan error),
}
Expand All @@ -275,7 +275,7 @@ func (es *EventSystem) subscribePendingLogs(crit quai.FilterQuery, logs chan []*
created: time.Now(),
logs: logs,
hashes: make(chan []common.Hash),
headers: make(chan *types.Header),
headers: make(chan *types.WorkObject),
installed: make(chan struct{}),
err: make(chan error),
}
Expand All @@ -284,7 +284,7 @@ func (es *EventSystem) subscribePendingLogs(crit quai.FilterQuery, logs chan []*

// SubscribeNewHeads creates a subscription that writes the header of a block that is
// imported in the chain.
func (es *EventSystem) SubscribeNewHeads(headers chan *types.Header) *Subscription {
func (es *EventSystem) SubscribeNewHeads(headers chan *types.WorkObject) *Subscription {
sub := &subscription{
id: rpc.NewID(),
typ: BlocksSubscription,
Expand All @@ -307,7 +307,7 @@ func (es *EventSystem) SubscribePendingTxs(hashes chan []common.Hash) *Subscript
created: time.Now(),
logs: make(chan []*types.Log),
hashes: hashes,
headers: make(chan *types.Header),
headers: make(chan *types.WorkObject),
installed: make(chan struct{}),
err: make(chan error),
}
Expand Down Expand Up @@ -361,7 +361,7 @@ func (es *EventSystem) handleTxsEvent(filters filterIndex, ev core.NewTxsEvent)

func (es *EventSystem) handleChainEvent(filters filterIndex, ev core.ChainEvent) {
for _, f := range filters[BlocksSubscription] {
f.headers <- ev.Block.Header()

Choose a reason for hiding this comment

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

delete .Header()

Copy link
Author

Choose a reason for hiding this comment

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

fixed

f.headers <- ev.Block
}
}

Expand Down
Loading