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

vdn: impl msg specs, support block/vote biz logic #2940

Open
wants to merge 9 commits into
base: develop_vdn
Choose a base branch
from

Conversation

galaio
Copy link
Contributor

@galaio galaio commented Mar 7, 2025

Description

This PR implements all BEP-525 msg specs, and support basic block/vote gossip msg business logic. The VDN can sync new blocks, and aggregate votes successfully now.

It also adds some abstract for gossip/RPC msg handler. see vdn/interfaces.go.

Now, you can use https://github.com/bnb-chain/node-deploy/tree/support-vdnp2p to setup a vdn-only cluster in local for testing.

Changes

Notable changes:

  • vdn: impl msg specs;
  • vdn: optimize gossip pubsub handler;
  • handler: support to handle vdn block/vote gossip msg;
  • init-network: support vdn only configuration;
  • ...

@galaio galaio requested review from MatusKysel and zzzckck March 7, 2025 07:33
@galaio galaio marked this pull request as ready for review March 7, 2025 07:42
Comment on lines +1 to +32
package vdn

import (
"bytes"
"io"

"github.com/ethereum/go-ethereum/rlp"
)

// EncodeToStream encode any msg by rlp
func EncodeToStream(msg interface{}, writer io.Writer) error {
return rlp.Encode(writer, msg)
}

// DecodeFromStream msg must be a pointer
func DecodeFromStream(msg interface{}, reader io.Reader) error {
return rlp.Decode(reader, msg)
}

// EncodeToBytes encode any msg by rlp
func EncodeToBytes(msg interface{}) ([]byte, error) {
buf := new(bytes.Buffer)
if err := rlp.Encode(buf, msg); err != nil {
return nil, err
}
return buf.Bytes(), nil
}

// DecodeFromBytes msg must be a pointer
func DecodeFromBytes(msg interface{}, data []byte) error {
return rlp.DecodeBytes(data, msg)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

can we use ssz? as this is complete new netwrok ssz is much better candidate encoding, if you need help with this let me know

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it's a new network, but introducing ssz encoding is a big thing, I prefer to use current RLP encoding now. May be we can discuss this more~

Comment on lines +163 to +193
func defaultTopicParams() *pubsub.TopicScoreParams {
decayEpoch := 5
decayEpochDuration := 5 * oneEpochDuration()
blocksInEpoch := blocksPerEpoch()
meshWeight := -0.717
invalidDecayPeriod := 50 * oneEpochDuration()
if !meshDeliveryIsScored {
// Set the mesh weight as zero as a temporary measure, so as to prevent
// the average nodes from being penalised.
meshWeight = 0
}
return &pubsub.TopicScoreParams{
TopicWeight: defaultTopicWeight,
TimeInMeshWeight: maxInMeshScore / inMeshCap(),
TimeInMeshQuantum: inMeshTime(),
TimeInMeshCap: inMeshCap(),
FirstMessageDeliveriesWeight: 1,
FirstMessageDeliveriesDecay: scoreDecay(20 * oneEpochDuration()),
FirstMessageDeliveriesCap: 23,
MeshMessageDeliveriesWeight: meshWeight,
MeshMessageDeliveriesDecay: scoreDecay(decayEpochDuration),
MeshMessageDeliveriesCap: float64(blocksInEpoch * uint64(decayEpoch)),
MeshMessageDeliveriesThreshold: float64(blocksInEpoch*uint64(decayEpoch)) / 10,
MeshMessageDeliveriesWindow: 2 * time.Second,
MeshMessageDeliveriesActivation: 4 * oneEpochDuration(),
MeshFailurePenaltyWeight: meshWeight,
MeshFailurePenaltyDecay: scoreDecay(decayEpochDuration),
InvalidMessageDeliveriesWeight: -140.4475,
InvalidMessageDeliveriesDecay: scoreDecay(invalidDecayPeriod),
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

how did you get this values? maybe some comment would be beneficial

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants