Skip to content

Commit

Permalink
feat(mimicry): add caps for mimicry
Browse files Browse the repository at this point in the history
  • Loading branch information
Savid committed Mar 8, 2024
1 parent 97a1a33 commit d460256
Show file tree
Hide file tree
Showing 13 changed files with 945 additions and 926 deletions.
1 change: 1 addition & 0 deletions example_mimicry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ coordinator:
# authorization: Someb64Value
# networkIds: [1]
# forkIdHashes: [0xf0afd0e3]
# capabilities: [eth/68]
# maxPeers: 100

outputs:
Expand Down
1 change: 1 addition & 0 deletions pkg/cannon/deriver/beacon/eth/v1/beacon_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ func (b *BeaconBlobDeriver) createEventFromBlob(ctx context.Context, blob *deneb
func (b *BeaconBlobDeriver) getAdditionalData(_ context.Context, blob *deneb.BlobSidecar) (*xatu.ClientMeta_AdditionalEthV1BeaconBlobSidecarData, error) {
extra := &xatu.ClientMeta_AdditionalEthV1BeaconBlobSidecarData{
DataSize: &wrapperspb.UInt64Value{Value: uint64(len(blob.Blob))},
DataEmptySize: &wrapperspb.UInt64Value{Value: uint64(ethereum.CountConsecutiveEmptyBytes(blob.Blob[:], 4))},
VersionedHash: ethereum.ConvertKzgCommitmentToVersionedHash(blob.KZGCommitment[:]).String(),
}

Expand Down
26 changes: 1 addition & 25 deletions pkg/cannon/deriver/beacon/eth/v2/execution_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func (b *ExecutionTransactionDeriver) processSlot(ctx context.Context, slot phas
for i := 0; i < len(transaction.BlobTxSidecar().Blobs); i++ {
sidecar := transaction.BlobTxSidecar().Blobs[i][:]
sidecarsSize += len(sidecar)
sidecarsEmptySize += countConsecutiveEmptyBytes(sidecar, 4)
sidecarsEmptySize += ethereum.CountConsecutiveEmptyBytes(sidecar, 4)
}

tx.BlobSidecarsSize = fmt.Sprint(sidecarsSize)
Expand All @@ -316,30 +316,6 @@ func (b *ExecutionTransactionDeriver) processSlot(ctx context.Context, slot phas
return events, nil
}

func countConsecutiveEmptyBytes(byteArray []byte, threshold int) int {
count := 0
consecutiveZeros := 0

for _, b := range byteArray {
if b == 0 {
consecutiveZeros++
} else {
if consecutiveZeros > threshold {
count += consecutiveZeros
}

consecutiveZeros = 0
}
}

// Check if the last sequence in the array is longer than the threshold and hasn't been counted yet
if consecutiveZeros > threshold {
count += consecutiveZeros
}

return count
}

func (b *ExecutionTransactionDeriver) getExecutionTransactions(ctx context.Context, block *spec.VersionedSignedBeaconBlock) ([]*types.Transaction, error) {
transactions := []*types.Transaction{}

Expand Down
24 changes: 24 additions & 0 deletions pkg/cannon/ethereum/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,27 @@ func ConvertKzgCommitmentToVersionedHash(commitment []byte) common.Hash {

return versionedHash
}

func CountConsecutiveEmptyBytes(byteArray []byte, threshold int) int {
count := 0
consecutiveZeros := 0

for _, b := range byteArray {
if b == 0 {
consecutiveZeros++
} else {
if consecutiveZeros > threshold {
count += consecutiveZeros
}

consecutiveZeros = 0
}
}

// Check if the last sequence in the array is longer than the threshold and hasn't been counted yet
if consecutiveZeros > threshold {
count += consecutiveZeros
}

return count
}
1 change: 1 addition & 0 deletions pkg/mimicry/coordinator/xatu/coordinator/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type Config struct {
TLS bool `yaml:"tls" default:"false"`
NetworkIds []uint64 `yaml:"networkIds"`
ForkIDHashes []string `yaml:"forkIdHashes"`
Capabilities []string `yaml:"capabilities"`
MaxPeers uint32 `yaml:"maxPeers" default:"100"`
}

Expand Down
1 change: 1 addition & 0 deletions pkg/mimicry/coordinator/xatu/coordinator/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func (c *Coordinator) CoordinateExecutionNodeRecords(ctx context.Context, record
req := xatu.CoordinateExecutionNodeRecordsRequest{
NetworkIds: c.config.NetworkIds,
ForkIdHashes: forkIDHashes,
Capabilities: c.config.Capabilities,
NodeRecords: records,
Limit: c.config.MaxPeers,
ClientId: c.name,
Expand Down
28 changes: 3 additions & 25 deletions pkg/mimicry/p2p/execution/event_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"github.com/sirupsen/logrus"
"google.golang.org/protobuf/types/known/timestamppb"
"google.golang.org/protobuf/types/known/wrapperspb"

"github.com/ethpandaops/xatu/pkg/cannon/ethereum"
)

func (p *Peer) handleTransaction(ctx context.Context, eventTime time.Time, event *types.Transaction) (*xatu.DecoratedEvent, error) {
Expand Down Expand Up @@ -103,7 +105,7 @@ func (p *Peer) getTransactionData(ctx context.Context, event *types.Transaction,
for i := 0; i < len(event.BlobTxSidecar().Blobs); i++ {
sidecar := event.BlobTxSidecar().Blobs[i][:]
sidecarsSize += len(sidecar)
sidecarsEmptySize += countConsecutiveEmptyBytes(sidecar, 4)
sidecarsEmptySize += ethereum.CountConsecutiveEmptyBytes(sidecar, 4)
}

extra.BlobSidecarsSize = fmt.Sprint(sidecarsSize)
Expand All @@ -113,30 +115,6 @@ func (p *Peer) getTransactionData(ctx context.Context, event *types.Transaction,
return extra, nil
}

func countConsecutiveEmptyBytes(byteArray []byte, threshold int) int {
count := 0
consecutiveZeros := 0

for _, b := range byteArray {
if b == 0 {
consecutiveZeros++
} else {
if consecutiveZeros > threshold {
count += consecutiveZeros
}

consecutiveZeros = 0
}
}

// Check if the last sequence in the array is longer than the threshold and hasn't been counted yet
if consecutiveZeros > threshold {
count += consecutiveZeros
}

return count
}

type TransactionHashItem struct {
Hash common.Hash
Seen time.Time
Expand Down
Loading

0 comments on commit d460256

Please sign in to comment.