public Task PublishAttestationAsync(Attestation signedAttestation) { // TODO: Basic validation before broadcasting, e.g. signature is correct ulong attestationSubnetIndex = (ulong)signedAttestation.Data.Index % _networkingConfigurationOptions.CurrentValue.AttestationSubnetCount; // TODO: Maybe cache the subnet topic UTF8 byte values (concurrent dictionary?) string topicTemplate = "/eth2/committee_index{0}_beacon_attestation/ssz"; string topic = string.Format(topicTemplate, attestationSubnetIndex); byte[] topicUtf8 = Encoding.UTF8.GetBytes(topic); Span <byte> encoded = new byte[Ssz.Ssz.AttestationLength(signedAttestation)]; Ssz.Ssz.Encode(encoded, signedAttestation); if (_logger.IsDebug()) { LogDebug.GossipSend(_logger, topic, encoded.Length, null); } if (!_mothraLibp2p.SendGossip(topicUtf8, encoded)) { if (_logger.IsWarn()) { Log.GossipNotPublishedAsPeeeringNotStarted(_logger, topic, null); } } return(Task.CompletedTask); }
public Task PublishBeaconBlockAsync(SignedBeaconBlock signedBlock) { // TODO: Validate signature before broadcasting (if not already validated) Span <byte> encoded = new byte[Ssz.Ssz.SignedBeaconBlockLength(signedBlock)]; Ssz.Ssz.Encode(encoded, signedBlock); if (_logger.IsDebug()) { LogDebug.GossipSend(_logger, nameof(TopicUtf8.BeaconBlock), encoded.Length, null); } if (!_mothraLibp2p.SendGossip(TopicUtf8.BeaconBlock, encoded)) { if (_logger.IsWarn()) { Log.GossipNotPublishedAsPeeeringNotStarted(_logger, nameof(TopicUtf8.BeaconBlock), null); } } return(Task.CompletedTask); }