rm StreamCodeAndCodeHash
This commit is contained in:
parent
60472965df
commit
fbc87c0410
11
README.md
11
README.md
@ -28,8 +28,7 @@ hash.
|
|||||||
State leaf nodes contain information about account changes, including whether they are removed, an
|
State leaf nodes contain information about account changes, including whether they are removed, an
|
||||||
account wrapper with account details and identifiers, and an array of storage leaf nodes
|
account wrapper with account details and identifiers, and an array of storage leaf nodes
|
||||||
representing storage changes. The IPLD type encapsulates CID-content pairs, used for code mappings
|
representing storage changes. The IPLD type encapsulates CID-content pairs, used for code mappings
|
||||||
and trie node (both intermediate and leaf) IPLD objects. Lastly, `CodeAndCodeHash` stores
|
and trie node (both intermediate and leaf) IPLD objects.
|
||||||
codehash-to-code mappings.
|
|
||||||
|
|
||||||
```go
|
```go
|
||||||
// Payload packages the data to send to state diff subscriptions
|
// Payload packages the data to send to state diff subscriptions
|
||||||
@ -79,12 +78,6 @@ type IPLD struct {
|
|||||||
CID string
|
CID string
|
||||||
Content []byte
|
Content []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
// CodeAndCodeHash struct to hold codehash => code mappings
|
|
||||||
type CodeAndCodeHash struct {
|
|
||||||
Hash common.Hash
|
|
||||||
Code []byte
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
@ -205,8 +198,6 @@ for {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Additionally, the `StreamCodeAndCodeHash` subscription method streams codehash-to-code pairs at a given block to a websocket channel.
|
|
||||||
|
|
||||||
#### Unary endpoints
|
#### Unary endpoints
|
||||||
|
|
||||||
The service also exposes unary RPC endpoints for retrieving the state diff `StateObject` for a specific block height/hash.
|
The service also exposes unary RPC endpoints for retrieving the state diff `StateObject` for a specific block height/hash.
|
||||||
|
26
api.go
26
api.go
@ -88,32 +88,6 @@ func (api *PublicAPI) StateDiffFor(ctx context.Context, blockHash common.Hash, p
|
|||||||
return api.sds.StateDiffFor(blockHash, params)
|
return api.sds.StateDiffFor(blockHash, params)
|
||||||
}
|
}
|
||||||
|
|
||||||
// StreamCodeAndCodeHash writes all of the codehash=>code pairs at a given block to a websocket channel.
|
|
||||||
func (api *PublicAPI) StreamCodeAndCodeHash(ctx context.Context, blockNumber uint64) (<-chan types.CodeAndCodeHash, error) {
|
|
||||||
payloadChan := make(chan types.CodeAndCodeHash, chainEventChanSize)
|
|
||||||
clientChan := make(chan types.CodeAndCodeHash, chainEventChanSize)
|
|
||||||
quitChan := make(chan bool, 1)
|
|
||||||
api.sds.StreamCodeAndCodeHash(blockNumber, payloadChan, quitChan)
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
defer close(clientChan)
|
|
||||||
defer close(payloadChan)
|
|
||||||
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case payload := <-payloadChan:
|
|
||||||
clientChan <- payload
|
|
||||||
case <-ctx.Done():
|
|
||||||
return
|
|
||||||
case <-quitChan:
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
return clientChan, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// WriteStateDiffAt writes a state diff object directly to DB at the specific blockheight
|
// WriteStateDiffAt writes a state diff object directly to DB at the specific blockheight
|
||||||
func (api *PublicAPI) WriteStateDiffAt(ctx context.Context, blockNumber uint64, params Params) JobID {
|
func (api *PublicAPI) WriteStateDiffAt(ctx context.Context, blockNumber uint64, params Params) JobID {
|
||||||
var err error
|
var err error
|
||||||
|
39
service.go
39
service.go
@ -31,7 +31,6 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
"github.com/ethereum/go-ethereum/trie"
|
|
||||||
plugeth "github.com/openrelayxyz/plugeth-utils/core"
|
plugeth "github.com/openrelayxyz/plugeth-utils/core"
|
||||||
"github.com/thoas/go-funk"
|
"github.com/thoas/go-funk"
|
||||||
|
|
||||||
@ -798,44 +797,6 @@ func (sds *Service) UnsubscribeWriteStatus(id SubID) {
|
|||||||
sds.jobStatusSubsMutex.Unlock()
|
sds.jobStatusSubsMutex.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// StreamCodeAndCodeHash subscription method for extracting all the codehash=>code mappings that exist in the trie at the provided height
|
|
||||||
func (sds *Service) StreamCodeAndCodeHash(blockNumber uint64, outChan chan<- types2.CodeAndCodeHash, quitChan chan<- bool) {
|
|
||||||
current := sds.BlockChain.GetBlockByNumber(blockNumber)
|
|
||||||
log.Info("sending code and codehash", "number", blockNumber)
|
|
||||||
currentTrie, err := sds.BlockChain.StateCache().OpenTrie(current.Root())
|
|
||||||
if err != nil {
|
|
||||||
log.Error("error getting trie for block", "number", current.Number(), "error", err)
|
|
||||||
close(quitChan)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
leafIt := trie.NewIterator(currentTrie.NodeIterator(nil))
|
|
||||||
go func() {
|
|
||||||
defer close(quitChan)
|
|
||||||
for leafIt.Next() {
|
|
||||||
select {
|
|
||||||
case <-sds.QuitChan:
|
|
||||||
return
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
account := new(types.StateAccount)
|
|
||||||
if err := rlp.DecodeBytes(leafIt.Value, account); err != nil {
|
|
||||||
log.Error("error decoding state account", "error", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
codeHash := common.BytesToHash(account.CodeHash)
|
|
||||||
code, err := sds.BlockChain.StateCache().ContractCode(codeHash)
|
|
||||||
if err != nil {
|
|
||||||
log.Error("error collecting contract code", "error", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
outChan <- types2.CodeAndCodeHash{
|
|
||||||
Hash: codeHash,
|
|
||||||
Code: code,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
// WatchAddress performs one of following operations on the watched addresses in sds.writeLoopParams and the db:
|
// WatchAddress performs one of following operations on the watched addresses in sds.writeLoopParams and the db:
|
||||||
// add | remove | set | clear
|
// add | remove | set | clear
|
||||||
func (sds *Service) WatchAddress(operation types2.OperationType, args []types2.WatchAddressArg) error {
|
func (sds *Service) WatchAddress(operation types2.OperationType, args []types2.WatchAddressArg) error {
|
||||||
|
@ -67,12 +67,6 @@ type IPLD struct {
|
|||||||
Content []byte
|
Content []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
// CodeAndCodeHash struct to hold codehash => code mappings
|
|
||||||
type CodeAndCodeHash struct {
|
|
||||||
Hash common.Hash
|
|
||||||
Code []byte
|
|
||||||
}
|
|
||||||
|
|
||||||
type StateNodeSink func(node StateLeafNode) error
|
type StateNodeSink func(node StateLeafNode) error
|
||||||
type StorageNodeSink func(node StorageLeafNode) error
|
type StorageNodeSink func(node StorageLeafNode) error
|
||||||
type IPLDSink func(IPLD) error
|
type IPLDSink func(IPLD) error
|
||||||
|
Loading…
Reference in New Issue
Block a user