rm StreamCodeAndCodeHash

This commit is contained in:
Roy Crihfield 2023-06-30 13:38:25 +08:00
parent 60472965df
commit fbc87c0410
4 changed files with 1 additions and 81 deletions

View File

@ -28,8 +28,7 @@ hash.
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
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
codehash-to-code mappings.
and trie node (both intermediate and leaf) IPLD objects.
```go
// Payload packages the data to send to state diff subscriptions
@ -79,12 +78,6 @@ type IPLD struct {
CID string
Content []byte
}
// CodeAndCodeHash struct to hold codehash => code mappings
type CodeAndCodeHash struct {
Hash common.Hash
Code []byte
}
```
## 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
The service also exposes unary RPC endpoints for retrieving the state diff `StateObject` for a specific block height/hash.

26
api.go
View File

@ -88,32 +88,6 @@ func (api *PublicAPI) StateDiffFor(ctx context.Context, blockHash common.Hash, p
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
func (api *PublicAPI) WriteStateDiffAt(ctx context.Context, blockNumber uint64, params Params) JobID {
var err error

View File

@ -31,7 +31,6 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/trie"
plugeth "github.com/openrelayxyz/plugeth-utils/core"
"github.com/thoas/go-funk"
@ -798,44 +797,6 @@ func (sds *Service) UnsubscribeWriteStatus(id SubID) {
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:
// add | remove | set | clear
func (sds *Service) WatchAddress(operation types2.OperationType, args []types2.WatchAddressArg) error {

View File

@ -67,12 +67,6 @@ type IPLD struct {
Content []byte
}
// CodeAndCodeHash struct to hold codehash => code mappings
type CodeAndCodeHash struct {
Hash common.Hash
Code []byte
}
type StateNodeSink func(node StateLeafNode) error
type StorageNodeSink func(node StorageLeafNode) error
type IPLDSink func(IPLD) error