diff --git a/blocksync/reactor.go b/blocksync/reactor.go index 980d3b048d3..f9a03713350 100644 --- a/blocksync/reactor.go +++ b/blocksync/reactor.go @@ -1,8 +1,6 @@ package blocksync import ( - "bytes" - "errors" "fmt" "reflect" "time" @@ -555,53 +553,6 @@ FOR_LOOP: err = bcR.blockExec.ValidateBlock(state, first) } - // make sure the block has valid batchHash and batchHeader, and has the enough valid BLS signatures if it is a batch point - if err == nil { - err = func() error { - // check the correctness of the relation of batchHash and batchHeader - if len(first.L2BatchHeader) > 0 { - batchHash, hashErr := bcR.l2Node.BatchHash(first.L2BatchHeader) - if hashErr != nil { - return hashErr - } - if !bytes.Equal(first.BatchHash, batchHash) { - return fmt.Errorf("wrong batchHash. expectedHash: %x, actualHash: %x, batchHeader: %x", batchHash, first.BatchHash, first.L2BatchHeader) - } - } else if len(first.BatchHash) > 0 { - return errors.New("batch hash can not exist when batchHeader is empty") - } - - blsDatas, err := l2node.GetBLSDatas(second.LastCommit, state.Validators) - if err != nil { - return err - } - var validVotingPowers int64 - if len(blsDatas) > 0 { - if len(first.BatchHash) == 0 { - return errors.New("should not have bls signatures when batchHash is empty") - } - for _, blsData := range blsDatas { - // todo currently can not ensure the l2node has the corresponding bls public key of the signer - //valid, err := bcR.l2Node.VerifySignature(blsData.Signer, first.BatchHash, blsData.Signature) - //if err != nil { - // return err - //} - //if valid { - // validVotingPowers += blsData.VotingPower - //} - validVotingPowers += blsData.VotingPower - } - quorum := state.Validators.TotalVotingPower()*2/3 + 1 - if validVotingPowers < quorum { - return fmt.Errorf("not enough votingPowers of valid bls signature. quorum: %d, valid votingPower: %d", quorum, validVotingPowers) - } - } else if len(first.BatchHash) > 0 { - return errors.New("must have bls signatures when batchHash is not empty") - } - return nil - }() - } - if err != nil { bcR.Logger.Error("Error in validation", "err", err) peerID := bcR.pool.RedoRequest(first.Height) diff --git a/blssignatures/bls_signatures.go b/blssignatures/bls_signatures.go deleted file mode 100644 index ccfa0099888..00000000000 --- a/blssignatures/bls_signatures.go +++ /dev/null @@ -1,258 +0,0 @@ -package blssignatures - -import ( - cryptorand "crypto/rand" - "encoding/base64" - "errors" - "math/big" - - "github.com/morph-l2/go-ethereum/crypto" - "github.com/morph-l2/go-ethereum/crypto/bls12381" -) - -type PublicKey struct { - Key *bls12381.PointG2 - ValidityProof *bls12381.PointG1 // if this is nil, key came from a trusted source -} - -type PrivateKey *big.Int - -type Signature *bls12381.PointG1 - -func GeneratePrivKeyString() (string, error) { - g2 := bls12381.NewG2() - privKey, err := cryptorand.Int(cryptorand.Reader, g2.Q()) - if err != nil { - return "", err - } - privKeyBytes := PrivateKeyToBytes(privKey) - encodedPrivKey := make([]byte, base64.StdEncoding.EncodedLen(len(privKeyBytes))) - base64.StdEncoding.Encode(encodedPrivKey, privKeyBytes) - return string(encodedPrivKey), nil -} - -func GenerateKeys() (PublicKey, PrivateKey, error) { - g2 := bls12381.NewG2() - privateKey, err := cryptorand.Int(cryptorand.Reader, g2.Q()) - if err != nil { - return PublicKey{}, nil, err - } - publicKey, err := PublicKeyFromPrivateKey(privateKey) - return publicKey, privateKey, err -} - -func PublicKeyFromPrivateKey(privateKey PrivateKey) (PublicKey, error) { - pubKey := &bls12381.PointG2{} - g2 := bls12381.NewG2() - g2.MulScalar(pubKey, g2.One(), privateKey) - proof, err := KeyValidityProof(pubKey, privateKey) - if err != nil { - return PublicKey{}, err - } - publicKey, err := NewPublicKey(pubKey, proof) - if err != nil { - return PublicKey{}, err - } - return publicKey, nil -} - -// KeyValidityProof is the key validity proof mechanism is sufficient to prevent rogue key attacks, if applied to all keys -// that come from untrusted sources. We use the private key to sign the public key, but in the -// signature algorithm we use a tweaked version of the hash-to-curve function so that the result cannot be -// re-used as an ordinary signature. -// -// For a proof that this is sufficient, see Theorem 1 in -// Ristenpart & Yilek, "The Power of Proofs-of-Possession: ..." from EUROCRYPT 2007. -func KeyValidityProof(pubKey *bls12381.PointG2, privateKey PrivateKey) (Signature, error) { - g2 := bls12381.NewG2() - return signMessage2(privateKey, g2.ToBytes(pubKey), true) -} - -func NewPublicKey(pubKey *bls12381.PointG2, validityProof *bls12381.PointG1) (PublicKey, error) { - g2 := bls12381.NewG2() - unverifiedPublicKey := PublicKey{pubKey, validityProof} - verified, err := verifySignature2(validityProof, g2.ToBytes(pubKey), unverifiedPublicKey, true) - if err != nil { - return PublicKey{}, err - } - if !verified { - return PublicKey{}, errors.New("public key validation failed") - } - return unverifiedPublicKey, nil -} - -func NewTrustedPublicKey(pubKey *bls12381.PointG2) PublicKey { - return PublicKey{pubKey, nil} -} - -func (pubKey PublicKey) ToTrusted() PublicKey { - if pubKey.ValidityProof == nil { - return pubKey - } - return NewTrustedPublicKey(pubKey.Key) -} - -func SignMessage(priv PrivateKey, message []byte) (Signature, error) { - return signMessage2(priv, message, false) -} - -func signMessage2(priv PrivateKey, message []byte, keyValidationMode bool) (Signature, error) { - pointOnCurve, err := hashToG1Curve(message, keyValidationMode) - if err != nil { - return nil, err - } - g1 := bls12381.NewG1() - result := &bls12381.PointG1{} - g1.MulScalar(result, pointOnCurve, priv) - return result, nil -} - -func VerifySignature(sig Signature, message []byte, publicKey PublicKey) (bool, error) { - return verifySignature2(sig, message, publicKey, false) -} - -func verifySignature2(sig Signature, message []byte, publicKey PublicKey, keyValidationMode bool) (bool, error) { - pointOnCurve, err := hashToG1Curve(message, keyValidationMode) - if err != nil { - return false, err - } - - engine := bls12381.NewPairingEngine() - engine.Reset() - engine.AddPair(pointOnCurve, publicKey.Key) - leftSide := engine.Result() - engine.AddPair(sig, engine.G2.One()) - rightSide := engine.Result() - return leftSide.Equal(rightSide), nil -} - -func AggregatePublicKeys(pubKeys []PublicKey) PublicKey { - g2 := bls12381.NewG2() - ret := g2.Zero() - for _, pk := range pubKeys { - g2.Add(ret, ret, pk.Key) - } - return NewTrustedPublicKey(ret) -} - -func AggregateSignatures(sigs []Signature) Signature { - g1 := bls12381.NewG1() - ret := g1.Zero() - for _, s := range sigs { - g1.Add(ret, ret, s) - } - return ret -} - -func VerifyAggregatedSignatureSameMessage(sig Signature, message []byte, pubKeys []PublicKey) (bool, error) { - return VerifySignature(sig, message, AggregatePublicKeys(pubKeys)) -} - -func VerifyAggregatedSignatureDifferentMessages(sig Signature, messages [][]byte, pubKeys []PublicKey) (bool, error) { - - if len(messages) != len(pubKeys) { - return false, errors.New("len(messages) does not match (len(pub keys) in verification") - } - engine := bls12381.NewPairingEngine() - engine.Reset() - for i, msg := range messages { - pointOnCurve, err := hashToG1Curve(msg, false) - if err != nil { - return false, err - } - engine.AddPair(pointOnCurve, pubKeys[i].Key) - } - leftSide := engine.Result() - - engine.Reset() - engine.AddPair(sig, engine.G2.One()) - rightSide := engine.Result() - return leftSide.Equal(rightSide), nil -} - -// This hashes a message to a [32]byte, then maps the result to the G1 curve using -// the Simplified Shallue-van de Woestijne-Ulas Method, described in Section 6.6.2 of -// https://tools.ietf.org/html/draft-irtf-cfrg-hash-to-curve-06 -// -// If keyValidationMode is true, this uses a tweaked version of the padding, -// so that the result will not collide with a result generated in an ordinary signature. -func hashToG1Curve(message []byte, keyValidationMode bool) (*bls12381.PointG1, error) { - var padding [16]byte - h := crypto.Keccak256(message) - if keyValidationMode { - // modify padding, for domain separation - padding[0] = 1 - } - g1 := bls12381.NewG1() - return g1.MapToCurve(append(padding[:], h...)) -} - -func PublicKeyToBytes(pub PublicKey) []byte { - g2 := bls12381.NewG2() - if pub.ValidityProof == nil { - return append([]byte{0}, g2.ToBytes(pub.Key)...) - } else { - keyBytes := g2.ToBytes(pub.Key) - sigBytes := SignatureToBytes(pub.ValidityProof) - if len(sigBytes) > 255 { - panic("validity proof too large to serialize") - } - return append(append([]byte{byte(len(sigBytes))}, sigBytes...), keyBytes...) - } -} - -func PublicKeyFromBytes(in []byte, trustedSource bool) (PublicKey, error) { - if len(in) == 0 { - return PublicKey{}, errors.New("tried to deserialize empty public key") - } - g2 := bls12381.NewG2() - proofLen := int(in[0]) - if proofLen == 0 { - if !trustedSource { - return PublicKey{}, errors.New("tried to deserialize unvalidated public key from untrusted source") - } - key, err := g2.FromBytes(in[1:]) - if err != nil { - return PublicKey{}, err - } - return NewTrustedPublicKey(key), nil - } else { - if len(in) < 1+proofLen { - return PublicKey{}, errors.New("invalid serialized public key") - } - g1 := bls12381.NewG1() - proofBytes := in[1 : 1+proofLen] - validityProof, err := g1.FromBytes(proofBytes) - if err != nil { - return PublicKey{}, err - } - keyBytes := in[1+proofLen:] - key, err := g2.FromBytes(keyBytes) - if err != nil { - return PublicKey{}, err - } - if trustedSource { - // Skip verification of the validity proof - return PublicKey{key, validityProof}, nil - } - return NewPublicKey(key, validityProof) - } -} - -func PrivateKeyToBytes(priv PrivateKey) []byte { - return ((*big.Int)(priv)).Bytes() -} - -func PrivateKeyFromBytes(in []byte) (PrivateKey, error) { - return new(big.Int).SetBytes(in), nil -} - -func SignatureToBytes(sig Signature) []byte { - g1 := bls12381.NewG1() - return g1.ToBytes(sig) -} - -func SignatureFromBytes(in []byte) (Signature, error) { - g1 := bls12381.NewG1() - return g1.FromBytes(in) -} diff --git a/blssignatures/bls_signatures_test.go b/blssignatures/bls_signatures_test.go deleted file mode 100644 index e91029c1fdc..00000000000 --- a/blssignatures/bls_signatures_test.go +++ /dev/null @@ -1,163 +0,0 @@ -package blssignatures - -import ( - "encoding/hex" - "math/rand" - "testing" - "time" - - "github.com/stretchr/testify/require" - - "github.com/tendermint/tendermint/blssignatures/util" -) - -func TestValidSignature(t *testing.T) { - pub, priv, err := GenerateKeys() - Require(t, err) - - message := []byte("The quick brown fox jumped over the lazy dog.") - sig, err := SignMessage(priv, message) - Require(t, err) - - verified, err := VerifySignature(sig, message, pub) - Require(t, err) - if !verified { - Fail(t, "valid signature failed to verify") - } -} - -func TestWrongMessageSignature(t *testing.T) { - pub, priv, err := GenerateKeys() - Require(t, err) - - message := []byte("The quick brown fox jumped over the lazy dog.") - sig, err := SignMessage(priv, message) - Require(t, err) - - verified, err := VerifySignature(sig, append(message, 3), pub) - Require(t, err) - if verified { - Fail(t, "signature check on wrong message didn't fail") - } -} - -func TestWrongKeySignature(t *testing.T) { - _, priv, err := GenerateKeys() - Require(t, err) - pub, _, err := GenerateKeys() - Require(t, err) - - message := []byte("The quick brown fox jumped over the lazy dog.") - sig, err := SignMessage(priv, message) - Require(t, err) - - verified, err := VerifySignature(sig, message, pub) - Require(t, err) - if verified { - Fail(t, "signature check with wrong public key didn't fail") - } -} - -const NumSignaturesToAggregate = 12 - -func TestSignatureAggregation(t *testing.T) { - message := []byte("The quick brown fox jumped over the lazy dog.") - pubKeys := []PublicKey{} - sigs := []Signature{} - for i := 0; i < NumSignaturesToAggregate; i++ { - pub, priv, err := GenerateKeys() - Require(t, err) - pubKeys = append(pubKeys, pub) - sig, err := SignMessage(priv, message) - Require(t, err) - sigs = append(sigs, sig) - } - - verified, err := VerifySignature(AggregateSignatures(sigs), message, AggregatePublicKeys(pubKeys)) - Require(t, err) - if !verified { - Fail(t, "First aggregated signature check failed") - } - - verified, err = VerifyAggregatedSignatureSameMessage(AggregateSignatures(sigs), message, pubKeys) - Require(t, err) - if !verified { - Fail(t, "Second aggregated signature check failed") - } -} - -func TestSignatureAggregationAnyOrder(t *testing.T) { - message := []byte("The quick brown fox jumped over the lazy dog.") - pubKeys := []PublicKey{} - sigs := []Signature{} - for i := 0; i < NumSignaturesToAggregate; i++ { - pub, priv, err := GenerateKeys() - Require(t, err) - pubKeys = append(pubKeys, pub) - sig, err := SignMessage(priv, message) - Require(t, err) - sigs = append(sigs, sig) - } - - rand.Seed(time.Now().UnixNano()) - rand.Shuffle(NumSignaturesToAggregate, func(i, j int) { sigs[i], sigs[j] = sigs[j], sigs[i] }) - rand.Shuffle(NumSignaturesToAggregate, func(i, j int) { pubKeys[i], pubKeys[j] = pubKeys[j], pubKeys[i] }) - - verified, err := VerifySignature(AggregateSignatures(sigs), message, AggregatePublicKeys(pubKeys)) - Require(t, err) - if !verified { - Fail(t, "First aggregated signature check failed") - } - - rand.Shuffle(NumSignaturesToAggregate, func(i, j int) { sigs[i], sigs[j] = sigs[j], sigs[i] }) - verified, err = VerifyAggregatedSignatureSameMessage(AggregateSignatures(sigs), message, pubKeys) - Require(t, err) - if !verified { - Fail(t, "Second aggregated signature check failed") - } -} - -func TestSignatureAggregationDifferentMessages(t *testing.T) { - messages := [][]byte{} - pubKeys := []PublicKey{} - sigs := []Signature{} - - for i := 0; i < NumSignaturesToAggregate; i++ { - msg := []byte{byte(i)} - pubKey, privKey, err := GenerateKeys() - Require(t, err) - sig, err := SignMessage(privKey, msg) - Require(t, err) - messages = append(messages, msg) - pubKeys = append(pubKeys, pubKey) - sigs = append(sigs, sig) - } - - verified, err := VerifyAggregatedSignatureDifferentMessages(AggregateSignatures(sigs), messages, pubKeys) - Require(t, err) - if !verified { - Fail(t, "First aggregated signature check failed") - } -} - -func TestGenerateKeys(t *testing.T) { - pub, priv, err := GenerateKeys() - require.NoError(t, err) - privKeyBytes := PrivateKeyToBytes(priv) - pubKeyBytes := PublicKeyToBytes(pub) - - println("PrivKey:") - println(hex.EncodeToString(privKeyBytes)) - println("PubKey:") - println(hex.EncodeToString(pubKeyBytes)) -} - -func Require(t *testing.T, err error, printables ...interface{}) { - t.Helper() - util.RequireImpl(t, err, printables...) -} - -func Fail(t *testing.T, printables ...interface{}) { - t.Helper() - util.FailImpl(t, printables...) -} diff --git a/blssignatures/file.go b/blssignatures/file.go deleted file mode 100644 index b2a682ccc81..00000000000 --- a/blssignatures/file.go +++ /dev/null @@ -1,55 +0,0 @@ -package blssignatures - -import ( - "fmt" - "os" - - tmjson "github.com/tendermint/tendermint/libs/json" - tmos "github.com/tendermint/tendermint/libs/os" - "github.com/tendermint/tendermint/libs/tempfile" -) - -type FileBLSKey struct { - PubKey []byte `json:"pub_key"` - PrivKey []byte `json:"priv_key"` -} - -func (blsKey FileBLSKey) Save(filePath string) { - if filePath == "" { - panic("cannot save bls key: filePath not set") - } - - jsonBytes, err := tmjson.MarshalIndent(blsKey, "", " ") - if err != nil { - panic(err) - } - - if err := tempfile.WriteFileAtomic(filePath, jsonBytes, 0600); err != nil { - panic(err) - } -} - -func GenFileBLSKey() *FileBLSKey { - pubKey, privKey, err := GenerateKeys() - if err != nil { - panic(err) - } - - return &FileBLSKey{ - PubKey: PublicKeyToBytes(pubKey), - PrivKey: PrivateKeyToBytes(privKey), - } -} - -func LoadBLSKey(filePath string) *FileBLSKey { - keyJSONBytes, err := os.ReadFile(filePath) - if err != nil { - tmos.Exit(err.Error()) - } - blsKey := FileBLSKey{} - if err := tmjson.Unmarshal(keyJSONBytes, &blsKey); err != nil { - tmos.Exit(fmt.Sprintf("Error reading PrivValidator key from %v: %v\n", filePath, err)) - } - - return &blsKey -} diff --git a/blssignatures/util/colors.go b/blssignatures/util/colors.go deleted file mode 100644 index 9a2f9467bad..00000000000 --- a/blssignatures/util/colors.go +++ /dev/null @@ -1,47 +0,0 @@ -package util - -import "fmt" - -var Red = "\033[31;1m" -var Blue = "\033[34;1m" -var Yellow = "\033[33;1m" -var Pink = "\033[38;5;161;1m" -var Mint = "\033[38;5;48;1m" -var Grey = "\033[90m" - -var Lime = "\033[38;5;119;1m" -var Lavender = "\033[38;5;183;1m" -var Maroon = "\033[38;5;124;1m" -var Orange = "\033[38;5;202;1m" - -var Clear = "\033[0;0m" - -func PrintBlue(args ...interface{}) { - print(Blue) - fmt.Print(args...) - println(Clear) -} - -func PrintGrey(args ...interface{}) { - print(Grey) - fmt.Print(args...) - println(Clear) -} - -func PrintMint(args ...interface{}) { - print(Mint) - fmt.Print(args...) - println(Clear) -} - -func PrintRed(args ...interface{}) { - print(Red) - fmt.Print(args...) - println(Clear) -} - -func PrintYellow(args ...interface{}) { - print(Yellow) - fmt.Print(args...) - println(Clear) -} diff --git a/blssignatures/util/pseudorandom.go b/blssignatures/util/pseudorandom.go deleted file mode 100644 index bddb7ed4497..00000000000 --- a/blssignatures/util/pseudorandom.go +++ /dev/null @@ -1,40 +0,0 @@ -package util - -import ( - "math/rand" - "testing" - - "github.com/morph-l2/go-ethereum/common" -) - -type PseudoRandomDataSource struct { - rand *rand.Rand -} - -// NewPseudoRandomDataSource is the pseudorandom source that repeats on different executions -// T param is to make sure it's only used in testing -func NewPseudoRandomDataSource(_ *testing.T, seed int64) *PseudoRandomDataSource { - return &PseudoRandomDataSource{ - rand: rand.New(rand.NewSource(seed)), - } -} - -func (r *PseudoRandomDataSource) GetHash() common.Hash { - var outHash common.Hash - r.rand.Read(outHash[:]) - return outHash -} - -func (r *PseudoRandomDataSource) GetAddress() common.Address { - return common.BytesToAddress(r.GetHash().Bytes()[:20]) -} - -func (r *PseudoRandomDataSource) GetUint64() uint64 { - return r.rand.Uint64() -} - -func (r *PseudoRandomDataSource) GetData(size int) []byte { - outArray := make([]byte, size) - r.rand.Read(outArray) - return outArray -} diff --git a/blssignatures/util/testhelpers.go b/blssignatures/util/testhelpers.go deleted file mode 100644 index ea6c1238574..00000000000 --- a/blssignatures/util/testhelpers.go +++ /dev/null @@ -1,85 +0,0 @@ -package util - -import ( - "math/rand" - "os" - "regexp" - "sync" - "testing" - - "github.com/morph-l2/go-ethereum/common" - "github.com/morph-l2/go-ethereum/log" -) - -// Fail a test should an error occur -func RequireImpl(t *testing.T, err error, printables ...interface{}) { - t.Helper() - if err != nil { - t.Fatal(Red, printables, err, Clear) - } -} - -func FailImpl(t *testing.T, printables ...interface{}) { - t.Helper() - t.Fatal(Red, printables, Clear) -} - -func RandomizeSlice(slice []byte) []byte { - _, err := rand.Read(slice) - if err != nil { - panic(err) - } - return slice -} - -func RandomAddress() common.Address { - var address common.Address - RandomizeSlice(address[:]) - return address -} - -type LogHandler struct { - mutex sync.Mutex - t *testing.T - records []log.Record - streamHandler log.Handler -} - -func (h *LogHandler) Log(record *log.Record) error { - if err := h.streamHandler.Log(record); err != nil { - return err - } - h.mutex.Lock() - defer h.mutex.Unlock() - h.records = append(h.records, *record) - return nil -} - -func (h *LogHandler) WasLogged(pattern string) bool { - re, err := regexp.Compile(pattern) - RequireImpl(h.t, err) - h.mutex.Lock() - defer h.mutex.Unlock() - for _, record := range h.records { - if re.MatchString(record.Msg) { - return true - } - } - return false -} - -func newLogHandler(t *testing.T) *LogHandler { - return &LogHandler{ - t: t, - records: make([]log.Record, 0), - streamHandler: log.StreamHandler(os.Stderr, log.TerminalFormat(false)), - } -} - -func InitTestLog(t *testing.T, level log.Lvl) *LogHandler { - handler := newLogHandler(t) - glogger := log.NewGlogHandler(handler) - glogger.Verbosity(level) - log.Root().SetHandler(glogger) - return handler -} diff --git a/cmd/tendermint/commands/init.go b/cmd/tendermint/commands/init.go index f329a072366..e2eae6eef6c 100644 --- a/cmd/tendermint/commands/init.go +++ b/cmd/tendermint/commands/init.go @@ -5,7 +5,6 @@ import ( "github.com/spf13/cobra" - "github.com/tendermint/tendermint/blssignatures" cfg "github.com/tendermint/tendermint/config" tmos "github.com/tendermint/tendermint/libs/os" tmrand "github.com/tendermint/tendermint/libs/rand" @@ -52,18 +51,6 @@ func initFilesWithConfig(config *cfg.Config) error { logger.Info("Generated node key", "path", nodeKeyFile) } - // bls key - blsKeyFile := config.BLSKeyFile() - var bls *blssignatures.FileBLSKey - if tmos.FileExists(blsKeyFile) { - bls = blssignatures.LoadBLSKey(blsKeyFile) - logger.Info("Found bls private key", "path", blsKeyFile) - } else { - bls = blssignatures.GenFileBLSKey() - bls.Save(blsKeyFile) - logger.Info("Generated bls key", "path", blsKeyFile) - } - // genesis file genFile := config.GenesisFile() if tmos.FileExists(genFile) { diff --git a/config/config.go b/config/config.go index 5219c21f8e8..cef0035a573 100644 --- a/config/config.go +++ b/config/config.go @@ -44,7 +44,6 @@ var ( defaultNodeKeyName = "node_key.json" defaultAddrBookName = "addrbook.json" - defaultBLSKeyName = "bls_key.json" defaultConfigFilePath = filepath.Join(defaultConfigDir, defaultConfigFileName) defaultGenesisJSONPath = filepath.Join(defaultConfigDir, defaultGenesisJSONName) @@ -53,7 +52,6 @@ var ( defaultNodeKeyPath = filepath.Join(defaultConfigDir, defaultNodeKeyName) defaultAddrBookPath = filepath.Join(defaultConfigDir, defaultAddrBookName) - defaultBLSKeyPath = filepath.Join(defaultConfigDir, defaultBLSKeyName) minSubscriptionBufferSize = 100 defaultSubscriptionBufferSize = 200 @@ -229,9 +227,6 @@ type BaseConfig struct { //nolint: maligned // A JSON file containing the private key to use for p2p authenticated encryption NodeKey string `mapstructure:"node_key_file"` - // Path to the JSON file containing bls key - BLSKey string `mapstructure:"bls_key_file"` - // Mechanism to connect to the ABCI application: socket | grpc ABCI string `mapstructure:"abci"` @@ -247,7 +242,6 @@ func DefaultBaseConfig() BaseConfig { PrivValidatorKey: defaultPrivValKeyPath, PrivValidatorState: defaultPrivValStatePath, NodeKey: defaultNodeKeyPath, - BLSKey: defaultBLSKeyPath, Moniker: defaultMoniker, ProxyApp: "tcp://127.0.0.1:26658", ABCI: "socket", @@ -294,11 +288,6 @@ func (cfg BaseConfig) NodeKeyFile() string { return rootify(cfg.NodeKey, cfg.RootDir) } -// BLSPrivKeyFile returns the full path to the bls_priv_key.json file -func (cfg BaseConfig) BLSKeyFile() string { - return rootify(cfg.BLSKey, cfg.RootDir) -} - // DBDir returns the full path to the database directory func (cfg BaseConfig) DBDir() string { return rootify(cfg.DBPath, cfg.RootDir) diff --git a/consensus/batch.go b/consensus/batch.go deleted file mode 100644 index 2cf16ac1c9c..00000000000 --- a/consensus/batch.go +++ /dev/null @@ -1,99 +0,0 @@ -package consensus - -import ( - "time" - - "github.com/tendermint/tendermint/crypto/tmhash" - - "github.com/tendermint/tendermint/types" -) - -// batchData is used to store the cached batchHash/batchHeader mapping to blockHash, preventing duplicated calculation -type batchData struct { - batchHash []byte - batchHeader []byte -} - -type BatchCache struct { - BatchStartHeight int64 - BatchStartTime time.Time - ParentBatchHeader []byte - BlocksSinceLastBatchPoint []*types.Block // Notice: order by desc - - BatchHashes map[[tmhash.Size]byte]batchData // blockHash -> batchData -} - -func NewBatchCache() *BatchCache { - return &BatchCache{ - ParentBatchHeader: make([]byte, 0), - BlocksSinceLastBatchPoint: make([]*types.Block, 0), - BatchHashes: make(map[[tmhash.Size]byte]batchData), - } -} - -func (bc *BatchCache) UpdateStartPoint(block *types.Block) { - bc.BatchStartHeight = block.Height - bc.BatchStartTime = block.Time - bc.ParentBatchHeader = block.L2BatchHeader - bc.BlocksSinceLastBatchPoint = []*types.Block{block} -} - -func (bc *BatchCache) AppendBlock(block *types.Block) { - bc.BlocksSinceLastBatchPoint = append(bc.BlocksSinceLastBatchPoint, block) -} - -func (bc *BatchCache) StoreBatchData(blockHash []byte, batchHash []byte, batchHeader []byte) { - var blockHashKey [tmhash.Size]byte - copy(blockHashKey[:], blockHash) - - bc.BatchHashes[blockHashKey] = batchData{ - batchHash: batchHash, - batchHeader: batchHeader, - } -} - -func (bc *BatchCache) ClearBatchData() { - bc.BatchHashes = make(map[[tmhash.Size]byte]batchData) -} - -func (bc *BatchCache) batchData(blockHash []byte) (batchData batchData, found bool) { - var blockHashKey [tmhash.Size]byte - copy(blockHashKey[:], blockHash) - batchData, found = bc.BatchHashes[blockHashKey] - return -} - -// currentHeight should be greater than InitialHeight -func (cs *State) getBatchStart() (int64, time.Time) { - if cs.batchCache != nil && cs.batchCache.BatchStartHeight != 0 { - return cs.batchCache.BatchStartHeight, cs.batchCache.BatchStartTime - } - if cs.batchCache == nil { - cs.batchCache = NewBatchCache() - } - - if cs.Height == cs.state.InitialHeight { // use genesis block as the first batch point - return 0, cs.state.LastBlockTime - } - - var blocksByDesc []*types.Block // stores the blocks from last batch point block(which is not included) to now - for i := cs.Height - 1; i >= cs.state.InitialHeight; i-- { - block := cs.blockStore.LoadBlock(i) - if block.IsBatchPoint() { - cs.batchCache.UpdateStartPoint(block) - break - } - if i == cs.state.InitialHeight { - cs.batchCache.UpdateStartPoint(block) - break - } - blocksByDesc = append(blocksByDesc, block) - } - - // reverse `blocksByDesc`, and append them to batch cache - for i := len(blocksByDesc) - 1; i >= 0; i-- { - cs.batchCache.AppendBlock(blocksByDesc[i]) - } - - return cs.batchCache.BatchStartHeight, cs.batchCache.BatchStartTime -} diff --git a/consensus/replay.go b/consensus/replay.go index dff352840ca..61dd227d600 100644 --- a/consensus/replay.go +++ b/consensus/replay.go @@ -475,7 +475,7 @@ func (h *Handshaker) replayBlocks( h.logger.Info("Applying block", "height", i) block := h.store.LoadBlock(i) - _, _, err = sm.ExecBlockOnL2Node(h.logger, l2node, block, nil, nil) + _, err = sm.ExecBlockOnL2Node(h.logger, l2node, block, nil) if err != nil { return nil, err } diff --git a/consensus/state.go b/consensus/state.go index 5a549873568..69819f8f673 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -12,11 +12,8 @@ import ( "github.com/tendermint/tendermint/upgrade" - tmbytes "github.com/tendermint/tendermint/libs/bytes" - "github.com/cosmos/gogoproto/proto" - "github.com/tendermint/tendermint/blssignatures" cfg "github.com/tendermint/tendermint/config" cstypes "github.com/tendermint/tendermint/consensus/types" "github.com/tendermint/tendermint/crypto" @@ -42,7 +39,6 @@ var ( ErrInvalidProposalPOLRound = errors.New("error invalid proposal POL round") ErrAddingVote = errors.New("error adding vote") ErrSignatureFoundInPastBlocks = errors.New("found signature from the same key") - ErrBLSSignatureInalvid = errors.New("bls signature invalid") errPubKeyIsNotSet = errors.New("pubkey is not set. Look for \"Can't get private validator pubkey\" errors") ) @@ -90,7 +86,6 @@ type State struct { // config details config *cfg.ConsensusConfig privValidator types.PrivValidator // for signing votes - blsPrivKey *blssignatures.PrivateKey // store blocks and commits blockStore sm.BlockStore @@ -113,9 +108,6 @@ type State struct { // to avoid extra requests to HSM privValidatorPubKey crypto.PubKey - // batchCache caches the block info. since last batch point - batchCache *BatchCache - // state changes may be triggered by: msgs from peers, // msgs from ourself, or by timeouts peerMsgQueue chan msgInfo @@ -298,13 +290,6 @@ func (cs *State) SetPrivValidator(priv types.PrivValidator) { } } -func (cs *State) SetBLSPrivKey(bls *blssignatures.PrivateKey) { - cs.mtx.Lock() - defer cs.mtx.Unlock() - - cs.blsPrivKey = bls -} - // SetTimeoutTicker sets the local timer. It may be useful to overwrite for // testing. func (cs *State) SetTimeoutTicker(timeoutTicker TimeoutTicker) { @@ -1299,80 +1284,14 @@ func (cs *State) createProposalBlock() (*types.Block, error) { cs.state, commit, proposerAddr, - func(l2BlockMeta tmbytes.HexBytes, txs types.Txs, blockHeight int64, blockTime time.Time) ([]byte, []byte) { - return cs.decideBatchPoint(l2BlockMeta, txs, blockHeight, blockTime) - }) + ) if err != nil { return nil, err } - cs.setTrustBatchData(ret.Hash(), ret.BatchHash, ret.L2BatchHeader) - return ret, nil } -func (cs *State) setTrustBatchData(blockHash tmbytes.HexBytes, batchHash, batchHeader []byte) { - cs.batchCache.StoreBatchData(blockHash, batchHash, batchHeader) -} - -func (cs *State) decideBatchPoint(l2BlockMeta tmbytes.HexBytes, txs types.Txs, blockHeight int64, blockTime time.Time) (batchHash []byte, batchHeader []byte) { - batchStartHeight, batchStartTime := cs.getBatchStart() - sizeExceeded, err := cs.l2Node.CalculateCapWithProposalBlock( - l2BlockMeta.Bytes(), - txs, - func() (parentBatchHeader []byte, blocksMeta [][]byte, transactions []types.Txs, err error) { - // cs.getBatchStart promised we have batch data cached in cs.batchCache - parentBatchHeader = cs.batchCache.ParentBatchHeader - historicBlocks := cs.batchCache.BlocksSinceLastBatchPoint - - blocksMeta = make([][]byte, len(historicBlocks)) - transactions = make([]types.Txs, len(historicBlocks)) - var transactionsCount int - for i, hb := range historicBlocks { - blocksMeta[i] = hb.L2BlockMeta - transactions[i] = hb.Txs - transactionsCount += hb.Txs.Len() - } - cs.Logger.Info("fetching blocks since last batch point", "lastBatchPoint", batchStartHeight, "blockCount", len(historicBlocks), "transactionTotalCount", transactionsCount) - return - }) - if err != nil { - panic(err) - } - cs.Logger.Info("decideBatchPoint", - "currentBlockHeight", blockHeight, - "batchStartHeight", batchStartHeight, - "currentBlockTime", blockTime.String(), - "batchStartTime", batchStartTime.String(), - "sizeExceeded", sizeExceeded, - "blocksIntervalParam", cs.state.ConsensusParams.Batch.BlocksInterval, - "TimeoutParam", cs.state.ConsensusParams.Batch.Timeout) - if blockHeight == 1 { - return - } - if sizeExceeded || - (cs.state.ConsensusParams.Batch.BlocksInterval > 0 && blockHeight-batchStartHeight >= cs.state.ConsensusParams.Batch.BlocksInterval) || - (cs.state.ConsensusParams.Batch.Timeout > 0 && blockTime.Sub(batchStartTime) >= cs.state.ConsensusParams.Batch.Timeout) { - batchHash, batchHeader, err = cs.l2Node.SealBatch() - if err != nil { - panic(err) - } - } - return batchHash, batchHeader -} - -func (cs *State) decideBatchPointWithProposedBlock(block *types.Block) (batchHash []byte, batchHeader []byte) { - if cs.batchCache != nil { - getBatchData, found := cs.batchCache.batchData(block.Hash()) - if found { - return getBatchData.batchHash, getBatchData.batchHeader - } - } - batchHash, batchHeader = cs.decideBatchPoint(block.L2BlockMeta, block.Txs, block.Height, block.Time) - cs.batchCache.StoreBatchData(block.Hash(), batchHash, batchHeader) - return -} - // Enter: `timeoutPropose` after entering Propose. // Enter: proposal block and POL is ready. // Prevote for LockedBlock if we're locked, or ProposalBlock if valid. @@ -1456,18 +1375,6 @@ func (cs *State) defaultDoPrevote(height int64, round int32) { } if cs.isValidator(cs.privValidatorPubKey.Address()) { - // Vote nil if found unexpected batchHash or batchHeader - batchHash, batchHeader := cs.decideBatchPointWithProposedBlock(cs.ProposalBlock) - if !bytes.Equal(batchHash, cs.ProposalBlock.BatchHash) { - logger.Error("prevote step: consensus deems this block invalid; prevoting nil", "reason", "unexpected batchHash", "expected", batchHash, "actual", cs.ProposalBlock.BatchHash) - cs.signAddVote(tmproto.PrevoteType, nil, nil, types.PartSetHeader{}) - return - } - if !bytes.Equal(batchHeader, cs.ProposalBlock.L2BatchHeader) { - logger.Error("prevote step: consensus deems this block invalid; prevoting nil", "reason", "unexpected batchHeader", "expected", batchHeader, "actual", cs.ProposalBlock.L2BatchHeader) - cs.signAddVote(tmproto.PrevoteType, nil, nil, types.PartSetHeader{}) - return - } // request l2node to check whether the block data is valid valid, err := cs.l2Node.CheckBlockData( l2node.ConvertTxsToBytes(cs.ProposalBlock.Data.Txs), @@ -1489,7 +1396,7 @@ func (cs *State) defaultDoPrevote(height int64, round int32) { // NOTE: the proposal signature is validated when it is received, // and the proposal block parts are validated as they are received (against the merkle hash in the proposal) logger.Debug("prevote step: ProposalBlock is valid") - cs.signAddVote(tmproto.PrevoteType, cs.ProposalBlock.Hash(), cs.ProposalBlock.BatchHash, cs.ProposalBlockParts.Header()) + cs.signAddVote(tmproto.PrevoteType, cs.ProposalBlock.Hash(), nil, cs.ProposalBlockParts.Header()) } // Enter: any +2/3 prevotes at next round. @@ -1604,7 +1511,7 @@ func (cs *State) enterPrecommit(height int64, round int32) { logger.Error("failed publishing event relock", "err", err) } - cs.signAddVote(tmproto.PrecommitType, blockID.Hash, cs.ProposalBlock.BatchHash, blockID.PartSetHeader) + cs.signAddVote(tmproto.PrecommitType, blockID.Hash, nil, blockID.PartSetHeader) return } @@ -1617,14 +1524,6 @@ func (cs *State) enterPrecommit(height int64, round int32) { panic(fmt.Sprintf("precommit step; +2/3 prevoted for an invalid block: %v", err)) } - if cs.isValidator(cs.privValidatorPubKey.Address()) { // currently we skip batchPoint check for non-validator - // Validate batch data. - batchHash, batchHeader := cs.decideBatchPointWithProposedBlock(cs.ProposalBlock) - if !bytes.Equal(batchHash, cs.ProposalBlock.BatchHash) || !bytes.Equal(batchHeader, cs.ProposalBlock.L2BatchHeader) { - panic(fmt.Sprintf("precommit step; +2/3 prevoted for an invalid block: %v", fmt.Errorf("unexpected batchData. expectedHash: %x, actualHash: %x", batchHash, cs.ProposalBlock.BatchHash))) - } - } - cs.LockedRound = round cs.LockedBlock = cs.ProposalBlock cs.LockedBlockParts = cs.ProposalBlockParts @@ -1633,7 +1532,7 @@ func (cs *State) enterPrecommit(height int64, round int32) { logger.Error("failed publishing event lock", "err", err) } - cs.signAddVote(tmproto.PrecommitType, blockID.Hash, cs.ProposalBlock.BatchHash, blockID.PartSetHeader) + cs.signAddVote(tmproto.PrecommitType, blockID.Hash, nil, blockID.PartSetHeader) return } @@ -1899,15 +1798,6 @@ func (cs *State) finalizeCommit(height int64) { // must be called before we update state cs.recordMetrics(height, block) - if cs.batchCache != nil { - cs.batchCache.ClearBatchData() - if block.IsBatchPoint() { // batch point - cs.batchCache.UpdateStartPoint(block) - cs.Logger.Debug("updated start point", "blockHeight", block.Height, "batchHash", block.BatchHash) - } else { - cs.batchCache.AppendBlock(block) - } - } // NewHeightStep! cs.updateToState(stateCopy) @@ -2293,42 +2183,11 @@ func (cs *State) addVote(vote *types.Vote, peerID p2p.ID, replay bool) (added bo return } - // check the bls signature before adding it to LastCommit - if len(vote.BlockID.BatchHash) > 0 { - if len(vote.BLSSignature) == 0 { - return false, errors.New("can not find bls signature while the batchHash is not empty") - } - pubKey := cs.Validators.Validators[vote.ValidatorIndex].PubKey.Bytes() - valid, err := cs.l2Node.VerifySignature(pubKey, vote.BlockID.BatchHash, vote.BLSSignature) - if err != nil { - cs.Logger.Error("failed to verify bls signature", "err", err) - return false, nil - } - if !valid { - return false, fmt.Errorf("%v. sig: %x, batchHash: %x, tmKey: %x", ErrBLSSignatureInalvid, vote.BLSSignature, vote.BlockID.BatchHash, pubKey) - } - } else if len(vote.BLSSignature) > 0 { - return false, errors.New("should not have bls signature while the batchHash is empty") - } - added, err = cs.LastCommit.AddVote(vote) if !added { return } - if len(vote.BlockID.BatchHash) > 0 { - _, val := cs.LastValidators.GetByAddress(vote.ValidatorAddress) - blsData := l2node.BlsData{ - Signer: val.PubKey.Bytes(), - Signature: vote.BLSSignature, - VotingPower: val.VotingPower, - } - - if err = cs.l2Node.AppendBlsData(vote.Height, vote.BlockID.BatchHash, blsData); err != nil { - cs.Logger.Error("failed to append blsData", "err", err) - } - } - cs.Logger.Debug("added vote to last precommits", "last_commit", cs.LastCommit.StringShort()) if err := cs.eventBus.PublishEventVote(types.EventDataVote{Vote: vote}); err != nil { return added, err @@ -2358,26 +2217,6 @@ func (cs *State) addVote(vote *types.Vote, peerID p2p.ID, replay bool) (added bo return } - // verify the bls signature if it exists - if vote.Type == tmproto.PrecommitType { - if len(vote.BlockID.BatchHash) > 0 { - if len(vote.BLSSignature) == 0 { - return false, fmt.Errorf("lack of bls signature of batchHash: %x", vote.BlockID.BatchHash) - } - pubKey := cs.Validators.Validators[vote.ValidatorIndex].PubKey.Bytes() - valid, err := cs.l2Node.VerifySignature(pubKey, vote.BlockID.BatchHash, vote.BLSSignature) - if err != nil { - return false, fmt.Errorf("failed to verify bls signature. err: %v", err) - } - - if !valid { - return false, fmt.Errorf("%v. sig: %x, batchHash: %x, tmKey: %x", ErrBLSSignatureInalvid, vote.BLSSignature, vote.BlockID.BatchHash, pubKey) - } - } else if len(vote.BLSSignature) > 0 { - return false, errors.New("should not have bls signature while the batchHash is empty") - } - } - height := cs.Height added, err = cs.Votes.AddVote(vote, peerID) if !added { @@ -2558,16 +2397,6 @@ func (cs *State) signVote( vote.Signature = v.Signature vote.Timestamp = v.Timestamp - if len(batchHash) != 0 { - sig, err := blssignatures.SignMessage( - *cs.blsPrivKey, - batchHash, - ) - if err != nil { - return nil, err - } - vote.BLSSignature = blssignatures.SignatureToBytes(sig) - } return vote, nil } diff --git a/consensus/wal_generator.go b/consensus/wal_generator.go index e97d6b29321..cda61a6563c 100644 --- a/consensus/wal_generator.go +++ b/consensus/wal_generator.go @@ -12,7 +12,6 @@ import ( db "github.com/tendermint/tm-db" "github.com/tendermint/tendermint/abci/example/kvstore" - "github.com/tendermint/tendermint/blssignatures" cfg "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/l2node" "github.com/tendermint/tendermint/libs/log" @@ -93,13 +92,6 @@ func WALGenerateNBlocks(t *testing.T, wr io.Writer, numBlocks int) (err error) { if privValidator != nil { consensusState.SetPrivValidator(privValidator) } - blsPrivKey, err := blssignatures.PrivateKeyFromBytes(blssignatures.LoadBLSKey(config.BLSKeyFile()).PrivKey) - if err != nil { - t.Error(err) - } - if privValidator != nil { - consensusState.SetBLSPrivKey(&blsPrivKey) - } // END OF COPY PASTE // set consensus wal to buffered WAL, which will write all incoming msgs to buffer diff --git a/evidence/pool_test.go b/evidence/pool_test.go index e4cff7c611c..c0ba1c7fd0e 100644 --- a/evidence/pool_test.go +++ b/evidence/pool_test.go @@ -413,7 +413,7 @@ func initializeBlockStore(db dbm.DB, state sm.State, valAddr []byte) (*store.Blo for i := int64(1); i <= state.LastBlockHeight; i++ { lastCommit := makeCommit(i-1, valAddr) - block := state.MakeBlock(i, test.MakeNTxs(i, 1), nil, lastCommit, nil, state.Validators.Proposer.Address, nil) // TODO + block := state.MakeBlock(i, test.MakeNTxs(i, 1), nil, lastCommit, nil, state.Validators.Proposer.Address) block.Header.Time = defaultEvidenceTime.Add(time.Duration(i) * time.Minute) block.Header.Version = tmversion.Consensus{Block: version.BlockProtocol, App: 1} const parts = 1 diff --git a/internal/test/block.go b/internal/test/block.go index 160da34f647..67e90afed22 100644 --- a/internal/test/block.go +++ b/internal/test/block.go @@ -93,7 +93,7 @@ func MakeHeader(t *testing.T, h *types.Header) *types.Header { } func MakeBlock(state sm.State) *types.Block { - return state.MakeBlock(state.LastBlockHeight+1, MakeNTxs(state.LastBlockHeight+1, 10), nil, new(types.Commit), nil, state.NextValidators.Proposer.Address, nil) // TODO + return state.MakeBlock(state.LastBlockHeight+1, MakeNTxs(state.LastBlockHeight+1, 10), nil, new(types.Commit), nil, state.NextValidators.Proposer.Address) } func MakeBlocks(n int, state sm.State, privVals []types.PrivValidator) ([]*types.Block, error) { @@ -106,7 +106,7 @@ func MakeBlocks(n int, state sm.State, privVals []types.PrivValidator) ([]*types if err != nil { return nil, err } - block := state.MakeBlock(height, MakeNTxs(height, 10), nil, lastCommit, nil, state.LastValidators.Proposer.Address, nil) // TODO + block := state.MakeBlock(height, MakeNTxs(height, 10), nil, lastCommit, nil, state.LastValidators.Proposer.Address) blocks[i] = block state.LastBlockID = blockID state.LastBlockHeight = height diff --git a/l2node/l2node.go b/l2node/l2node.go index b6bf45a681a..1e1bc21365b 100644 --- a/l2node/l2node.go +++ b/l2node/l2node.go @@ -1,9 +1,6 @@ package l2node import ( - "fmt" - - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/tendermint/tendermint/types" ) @@ -11,7 +8,6 @@ import ( type BlockV2 = types.BlockV2 type L2Node interface { - Batcher RequestHeight( tmHeight int64, ) ( @@ -48,20 +44,10 @@ type L2Node interface { blockMeta []byte, consensusData ConsensusData, ) ( - nextBatchParams *tmproto.BatchParams, // set nil if no update nextValidatorSet [][]byte, err error, ) - VerifySignature( - tmKey []byte, - message []byte, // batch context hash - signature []byte, - ) ( - valid bool, - err error, - ) - // ==================== V2 Methods for Sequencer Mode ==================== // These methods are used after the upgrade to centralized sequencer mode. // They operate on BlockV2 (based on ExecutableL2Data) instead of raw txs/blockMeta. @@ -83,54 +69,8 @@ type L2Node interface { GetLatestBlockV2() (*BlockV2, error) } -// Batcher is used to pack the blocks into a batch, and commit the batch if it is determined to be a batchPoint. -type Batcher interface { - CalculateCapWithProposalBlock( - proposalBlockBytes []byte, - proposalTxs types.Txs, - get GetFromBatchStartFunc, - ) ( - sizeExceeded bool, - err error, - ) - - SealBatch() ( - batchHash []byte, - batchHeader []byte, - err error, - ) - - CommitBatch( - currentBlockBytes []byte, - currentTxs types.Txs, - blsDatas []BlsData, - ) error - - PackCurrentBlock( - currentBlockBytes []byte, - currentTxs types.Txs, - ) error - - AppendBlsData(height int64, batchHash []byte, data BlsData) error - - BatchHash(batchHeader []byte) ([]byte, error) -} -type GetFromBatchStartFunc func() ( - parentBatchHeader []byte, - blockMetas [][]byte, - transactions []types.Txs, - err error, -) - type ConsensusData struct { ValidatorSet [][]byte - BatchHash []byte -} - -type BlsData struct { - Signer []byte - Signature []byte - VotingPower int64 } func ConvertBytesToTxs(txs [][]byte) []types.Tx { @@ -148,21 +88,3 @@ func ConvertTxsToBytes(txs []types.Tx) [][]byte { } return s } - -func GetBLSDatas(commit *types.Commit, validators *types.ValidatorSet) (blsDatas []BlsData, err error) { - for _, signature := range commit.Signatures { - if len(signature.BLSSignature) > 0 { - _, validator := validators.GetByAddress(signature.ValidatorAddress) - if validator == nil { - err = fmt.Errorf("no validator found by addresss: %x", signature.ValidatorAddress) - return - } - blsDatas = append(blsDatas, BlsData{ - Signer: validator.PubKey.Bytes(), - Signature: signature.BLSSignature, - VotingPower: validator.VotingPower, - }) - } - } - return -} diff --git a/l2node/mock.go b/l2node/mock.go index 124268284fd..b5cbf3354d0 100644 --- a/l2node/mock.go +++ b/l2node/mock.go @@ -2,40 +2,25 @@ package l2node import ( "encoding/binary" - "errors" "fmt" "os" - "github.com/tendermint/tendermint/crypto/tmhash" tmjson "github.com/tendermint/tendermint/libs/json" tmos "github.com/tendermint/tendermint/libs/os" tmrand "github.com/tendermint/tendermint/libs/rand" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - "github.com/tendermint/tendermint/types" ) var _ L2Node = &MockL2Node{} -var genesisParentBatchHeader = []byte{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} - type MockL2Node struct { - TxNumber int - ValidatorSetFile string // used to control the validator set updates - genesisParentBatchHeader []byte - - parentBatchHeader []byte - encodingBatch []byte // parentBatchHeader|block|txs|...|block|txs|... - currentBlockWithTxsBytes []byte - sealedBatchHeader []byte - committedBatches map[[tmhash.Size]byte][]byte // batchHash -> batchHeader + TxNumber int + ValidatorSetFile string // used to control the validator set updates } func NewMockL2Node(n int, validatorSetFile string) L2Node { return &MockL2Node{ - TxNumber: n, - ValidatorSetFile: validatorSetFile, - genesisParentBatchHeader: genesisParentBatchHeader, - committedBatches: make(map[[tmhash.Size]byte][]byte), + TxNumber: n, + ValidatorSetFile: validatorSetFile, } } @@ -113,7 +98,6 @@ func (l *MockL2Node) DeliverBlock( meta []byte, consensusData ConsensusData, ) ( - nextBatchParams *tmproto.BatchParams, nextValidatorSet [][]byte, err error, ) { @@ -142,107 +126,7 @@ func (l *MockL2Node) DeliverBlock( }() } - return nextBatchParams, nextValidatorSet, err -} - -func (l *MockL2Node) VerifySignature( - tmKey []byte, - message []byte, - signature []byte, -) ( - valid bool, - err error, -) { - return true, nil -} - -func (l *MockL2Node) CalculateCapWithProposalBlock( - proposalBlockBytes []byte, - proposalTxs types.Txs, - get GetFromBatchStartFunc, -) ( - sizeExceeded bool, - err error, -) { - if len(proposalBlockBytes) < 8 { - return false, errors.New("empty block bytes") - } - if len(l.encodingBatch) == 0 { - parentBatchHeader, blockMetas, transactions, err := get() - if err != nil { - return false, err - } - if len(parentBatchHeader) == 0 { - l.parentBatchHeader = l.genesisParentBatchHeader - } else { - l.parentBatchHeader = parentBatchHeader - } - l.encodingBatch = append(l.encodingBatch, l.parentBatchHeader...) - for i, blockMeta := range blockMetas { - l.encodingBatch = append(l.encodingBatch, blockMeta...) - for _, tx := range transactions[i] { - l.encodingBatch = append(l.encodingBatch, tx...) - } - } - } - l.currentBlockWithTxsBytes = proposalBlockBytes - for _, tx := range proposalTxs { - l.currentBlockWithTxsBytes = append(l.currentBlockWithTxsBytes, tx...) - } - return len(l.encodingBatch)+len(l.currentBlockWithTxsBytes) > 1024, err -} - -func (l *MockL2Node) SealBatch() ([]byte, []byte, error) { - if len(l.encodingBatch) < 32+8 { // header length + 1 blockMeta length(8bytes) - return nil, nil, errors.New("wrong length batch") - } - batchHeader := l.encodingBatch[8:40] // make sure header has 32 bytes - batchHash := tmhash.Sum(batchHeader) - - l.sealedBatchHeader = batchHeader - return batchHash, batchHeader, nil -} - -func (l *MockL2Node) CommitBatch( - currentBlockBytes []byte, - currentTxs types.Txs, - datas []BlsData, -) error { - if len(l.sealedBatchHeader) == 0 { - return nil - } - batchHeader := l.sealedBatchHeader - batchHashBytes := tmhash.Sum(batchHeader) - var batchHash [tmhash.Size]byte - copy(batchHash[:], batchHashBytes) - - // commit current batch header - // update parentBatchHeader to committed batch header - // move current block bytes to a new batch - // remove previous sealedBatchHeader - l.committedBatches[batchHash] = batchHeader - l.parentBatchHeader = batchHeader - l.encodingBatch = append(l.parentBatchHeader, l.currentBlockWithTxsBytes...) - l.currentBlockWithTxsBytes = nil - l.sealedBatchHeader = nil - return nil -} - -func (l *MockL2Node) PackCurrentBlock( - currentBlockBytes []byte, - currentTxs types.Txs, -) error { - l.encodingBatch = append(l.encodingBatch, l.currentBlockWithTxsBytes...) - l.currentBlockWithTxsBytes = nil - return nil -} - -func (l *MockL2Node) AppendBlsData(height int64, batchHash []byte, data BlsData) error { - return nil -} - -func (l *MockL2Node) BatchHash(batchHeader []byte) ([]byte, error) { - return tmhash.Sum(batchHeader), nil + return nextValidatorSet, err } // ==================== V2 Methods for Sequencer Mode ==================== diff --git a/node/node.go b/node/node.go index 8daca33aa92..7d2b97e8d8b 100644 --- a/node/node.go +++ b/node/node.go @@ -19,7 +19,6 @@ import ( abci "github.com/tendermint/tendermint/abci/types" bc "github.com/tendermint/tendermint/blocksync" - "github.com/tendermint/tendermint/blssignatures" cfg "github.com/tendermint/tendermint/config" cs "github.com/tendermint/tendermint/consensus" "github.com/tendermint/tendermint/crypto" @@ -27,7 +26,6 @@ import ( "github.com/tendermint/tendermint/l2node" tmjson "github.com/tendermint/tendermint/libs/json" "github.com/tendermint/tendermint/libs/log" - tmos "github.com/tendermint/tendermint/libs/os" tmpubsub "github.com/tendermint/tendermint/libs/pubsub" "github.com/tendermint/tendermint/libs/service" "github.com/tendermint/tendermint/light" @@ -103,20 +101,10 @@ func DefaultNewNode(config *cfg.Config, logger log.Logger) (*Node, error) { return nil, fmt.Errorf("failed to load or gen node key %s: %w", config.NodeKeyFile(), err) } - if !tmos.FileExists(config.BLSKey) { - blssignatures.GenFileBLSKey().Save(config.BLSKeyFile()) - } - - blsPrivKey, err := blssignatures.PrivateKeyFromBytes(blssignatures.LoadBLSKey(config.BLSKeyFile()).PrivKey) - if err != nil { - return nil, fmt.Errorf("failed to load bls priv key") - } - return NewNode( config, l2node.NewMockL2Node(1, ""), privval.LoadOrGenFilePV(config.PrivValidatorKeyFile(), config.PrivValidatorStateFile()), - &blsPrivKey, nodeKey, proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir()), DefaultGenesisDocProviderFunc(config), @@ -217,7 +205,6 @@ type Node struct { config *cfg.Config genesisDoc *types.GenesisDoc // initial validator set privValidator types.PrivValidator // local node's validator key - blsPrivKey blssignatures.PrivateKey // network transport *p2p.MultiplexTransport @@ -466,7 +453,6 @@ func createConsensusReactor( notifier *l2node.Notifier, evidencePool *evidence.Pool, privValidator types.PrivValidator, - blsPrivKey *blssignatures.PrivateKey, csMetrics *cs.Metrics, waitSync bool, eventBus *types.EventBus, @@ -489,9 +475,6 @@ func createConsensusReactor( if privValidator != nil { consensusState.SetPrivValidator(privValidator) } - if blsPrivKey != nil { - consensusState.SetBLSPrivKey(blsPrivKey) - } consensusReactor := cs.NewReactor(consensusState, waitSync, cs.ReactorMetrics(csMetrics)) consensusReactor.SetLogger(consensusLogger) // services which will be publishing and/or subscribing for messages (events) @@ -776,7 +759,6 @@ func NewNode( config *cfg.Config, l2Node l2node.L2Node, privValidator types.PrivValidator, - blsPrivKey *blssignatures.PrivateKey, nodeKey *p2p.NodeKey, clientCreator proxy.ClientCreator, genesisDocProvider GenesisDocProvider, @@ -905,7 +887,7 @@ func NewNode( } consensusReactor, consensusState := createConsensusReactor( l2Node, config, state, blockExec, blockStore, notifier, - evidencePool, privValidator, blsPrivKey, csMetrics, + evidencePool, privValidator, csMetrics, stateSync || blockSync, eventBus, consensusLogger, ) @@ -978,7 +960,6 @@ func NewNode( config: config, genesisDoc: genDoc, privValidator: privValidator, - blsPrivKey: *blsPrivKey, transport: transport, sw: sw, diff --git a/rpc/test/helpers.go b/rpc/test/helpers.go index 0bf239c3e26..0cc19f182e3 100644 --- a/rpc/test/helpers.go +++ b/rpc/test/helpers.go @@ -9,7 +9,6 @@ import ( "time" abci "github.com/tendermint/tendermint/abci/types" - "github.com/tendermint/tendermint/blssignatures" "github.com/tendermint/tendermint/libs/log" cfg "github.com/tendermint/tendermint/config" @@ -164,11 +163,6 @@ func NewTendermint(app abci.Application, opts *Options) *nm.Node { pvKeyStateFile := config.PrivValidatorStateFile() pv := privval.LoadOrGenFilePV(pvKeyFile, pvKeyStateFile) - blsPrivKey, err := blssignatures.PrivateKeyFromBytes(blssignatures.LoadBLSKey(config.BLSKeyFile()).PrivKey) - if err != nil { - panic(err) - } - papp := proxy.NewLocalClientCreator(app) nodeKey, err := p2p.LoadOrGenNodeKey(config.NodeKeyFile()) if err != nil { @@ -178,13 +172,14 @@ func NewTendermint(app abci.Application, opts *Options) *nm.Node { config, nil, pv, - &blsPrivKey, nodeKey, papp, nm.DefaultGenesisDocProviderFunc(config), nm.DefaultDBProvider, nm.DefaultMetricsProvider(config.Instrumentation), logger, + nil, + nil, ) if err != nil { panic(err) diff --git a/state/execution.go b/state/execution.go index fc8aad24901..0a91b1a5f45 100644 --- a/state/execution.go +++ b/state/execution.go @@ -111,7 +111,6 @@ func (blockExec *BlockExecutor) CreateProposalBlock( state State, commit *types.Commit, proposerAddr []byte, - decideBatchPoint decideBatchPointFunc, ) ( *types.Block, error, ) { @@ -145,7 +144,7 @@ func (blockExec *BlockExecutor) CreateProposalBlock( } } - block := state.MakeBlock(height, l2node.ConvertBytesToTxs(txs), blockMeta, commit, evidence, proposerAddr, nil) // set 'decideBatchPoint' to nil here to prevent duplicated execution. + block := state.MakeBlock(height, l2node.ConvertBytesToTxs(txs), blockMeta, commit, evidence, proposerAddr) localLastCommit := buildLastCommitInfo(block, blockExec.store, state.InitialHeight) rpp, err := blockExec.proxyApp.PrepareProposalSync( @@ -173,7 +172,7 @@ func (blockExec *BlockExecutor) CreateProposalBlock( return nil, err } - return state.MakeBlock(height, txl, blockMeta, commit, evidence, proposerAddr, decideBatchPoint), nil + return state.MakeBlock(height, txl, blockMeta, commit, evidence, proposerAddr), nil } func (blockExec *BlockExecutor) ProcessProposal( @@ -237,14 +236,14 @@ func (blockExec *BlockExecutor) ApplyBlock( nextValidators := state.NextValidators.GetPubKeyBytesList() if blockExec.l2Node != nil { startTime := time.Now().UnixNano() - nextBatchParams, nextValidatorSet, err := ExecBlockOnL2Node(blockExec.logger, blockExec.l2Node, block, state.Validators, commit) + nextValidatorSet, err := ExecBlockOnL2Node(blockExec.logger, blockExec.l2Node, block, state.Validators) endTime := time.Now().UnixNano() blockExec.metrics.BlockProcessingTime.Observe(float64(endTime-startTime) / 1000000) if err != nil { return state, 0, err } - consensusParamUpdates = blockExec.GetConsensusParamsUpdate(nextBatchParams, nil, nil, nil, nil) + consensusParamUpdates = blockExec.GetConsensusParamsUpdate(nil, nil, nil, nil) validatorUpdates = blockExec.GetValidatorUpdates(nextValidatorSet, nextValidators) } @@ -288,17 +287,18 @@ func (blockExec *BlockExecutor) ApplyBlock( } func (blockExec *BlockExecutor) GetConsensusParamsUpdate( - nextBatchParams *tmproto.BatchParams, block *tmproto.BlockParams, evidence *tmproto.EvidenceParams, validator *tmproto.ValidatorParams, version *tmproto.VersionParams, ) *tmproto.ConsensusParams { - if nextBatchParams == nil && block == nil && evidence == nil && validator == nil && version == nil { + if block == nil && evidence == nil && validator == nil && version == nil { return nil } + // proto-level Batch field is intentionally omitted: sequencer batch + // generation is removed and the proto field exists only for wire compat + // (see types.ConsensusParams docs and Update/FromProto). return &tmproto.ConsensusParams{ - Batch: nextBatchParams, Block: block, Evidence: evidence, Validator: validator, @@ -387,45 +387,25 @@ func (blockExec *BlockExecutor) Commit( //--------------------------------------------------------- // Helper functions for executing blocks and updating state -func ExecBlockOnL2Node(logger log.Logger, l2Node l2node.L2Node, block *types.Block, validatorSet *types.ValidatorSet, commit *types.Commit) (*tmproto.BatchParams, [][]byte, error) { +func ExecBlockOnL2Node(logger log.Logger, l2Node l2node.L2Node, block *types.Block, validatorSet *types.ValidatorSet) ([][]byte, error) { var validators [][]byte if validatorSet != nil { validators = validatorSet.GetPubKeyBytesList() } - nextBatchParams, nextValidatorSet, err := l2Node.DeliverBlock( + nextValidatorSet, err := l2Node.DeliverBlock( l2node.ConvertTxsToBytes(block.Data.Txs), block.L2BlockMeta, l2node.ConsensusData{ ValidatorSet: validators, - BatchHash: block.BatchHash, }, ) if err != nil { logger.Error("failed to deliver block", "err", err, "height", block.Height) - return nil, nil, err - } - - // batch operation - if commit != nil { - blsDatas, err := l2node.GetBLSDatas(commit, validatorSet) - if err != nil { - panic(err) - } - if len(block.BatchHash) > 0 { // this is a batchPoint - if err = l2Node.CommitBatch(block.L2BlockMeta, block.Txs, blsDatas); err != nil { - logger.Error("failed to commit batch", "err", err, "height", block.Height) - return nil, nil, err - } - } else { - if err = l2Node.PackCurrentBlock(block.L2BlockMeta, block.Txs); err != nil { - logger.Error("failed to pack current block", "err", err, "height", block.Height) - return nil, nil, err - } - } + return nil, err } - return nextBatchParams, nextValidatorSet, nil + return nextValidatorSet, nil } // Executes block's transactions on proxyAppConn. diff --git a/state/state.go b/state/state.go index 36e4875a9ab..9ffac7d2917 100644 --- a/state/state.go +++ b/state/state.go @@ -7,8 +7,6 @@ import ( "os" "time" - tmbytes "github.com/tendermint/tendermint/libs/bytes" - "github.com/cosmos/gogoproto/proto" tmstate "github.com/tendermint/tendermint/proto/tendermint/state" @@ -240,7 +238,6 @@ func (state State) MakeBlock( lastCommit *types.Commit, evidence []types.Evidence, proposerAddress []byte, - decideBatchPoint decideBatchPointFunc, ) *types.Block { // Set time. @@ -251,13 +248,10 @@ func (state State) MakeBlock( timestamp = MedianTime(lastCommit, state.LastValidators) } - var batchHash, batchHeader []byte - if decideBatchPoint != nil { - batchHash, batchHeader = decideBatchPoint(blockMeta, txs, height, timestamp) - } - - // Build base block with block data. - block := types.MakeBlock(height, txs, blockMeta, batchHash, batchHeader, lastCommit, evidence) + // Build base block with block data. New blocks no longer carry batch data; + // the batchHash / batchHeader fields are retained on the wire (default nil) + // so historical block hashes remain byte-identical. + block := types.MakeBlock(height, txs, blockMeta, nil, nil, lastCommit, evidence) // Fill rest of header with state data. block.Header.Populate( @@ -367,5 +361,3 @@ func MakeGenesisState(genDoc *types.GenesisDoc) (State, error) { AppHash: genDoc.AppHash, }, nil } - -type decideBatchPointFunc func(l2BlockMeta tmbytes.HexBytes, txs types.Txs, blockHeight int64, blockTime time.Time) ([]byte, []byte) diff --git a/store/store_test.go b/store/store_test.go index bf31f4302bf..bc8a4814033 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -138,7 +138,7 @@ func TestMain(m *testing.M) { var cleanup cleanupFunc var err error state, _, cleanup = makeStateAndBlockStore(log.NewTMLogger(new(bytes.Buffer))) - block = state.MakeBlock(state.LastBlockHeight+1, test.MakeNTxs(state.LastBlockHeight+1, 10), nil, new(types.Commit), nil, state.Validators.GetProposer().Address, nil) // TODO + block = state.MakeBlock(state.LastBlockHeight+1, test.MakeNTxs(state.LastBlockHeight+1, 10), nil, new(types.Commit), nil, state.Validators.GetProposer().Address) partSet, err = block.MakePartSet(2) if err != nil { @@ -169,7 +169,7 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) { } // save a block - block := state.MakeBlock(bs.Height()+1, nil, nil, new(types.Commit), nil, state.Validators.GetProposer().Address, nil) // TODO + block := state.MakeBlock(bs.Height()+1, nil, nil, new(types.Commit), nil, state.Validators.GetProposer().Address) validPartSet, err := block.MakePartSet(2) require.NoError(t, err) seenCommit := makeTestCommit(10, tmtime.Now()) @@ -375,7 +375,7 @@ func TestLoadBaseMeta(t *testing.T) { bs := NewBlockStore(dbm.NewMemDB()) for h := int64(1); h <= 10; h++ { - block := state.MakeBlock(h, test.MakeNTxs(h, 10), nil, new(types.Commit), nil, state.Validators.GetProposer().Address, nil) // TODO + block := state.MakeBlock(h, test.MakeNTxs(h, 10), nil, new(types.Commit), nil, state.Validators.GetProposer().Address) partSet, err := block.MakePartSet(2) require.NoError(t, err) seenCommit := makeTestCommit(h, tmtime.Now()) @@ -446,7 +446,7 @@ func TestPruneBlocks(t *testing.T) { // make more than 1000 blocks, to test batch deletions for h := int64(1); h <= 1500; h++ { - block := state.MakeBlock(h, test.MakeNTxs(h, 10), nil, new(types.Commit), nil, state.Validators.GetProposer().Address, nil) // TODO + block := state.MakeBlock(h, test.MakeNTxs(h, 10), nil, new(types.Commit), nil, state.Validators.GetProposer().Address) partSet, err := block.MakePartSet(2) require.NoError(t, err) seenCommit := makeTestCommit(h, tmtime.Now()) @@ -563,7 +563,7 @@ func TestLoadBlockMetaByHash(t *testing.T) { require.NoError(t, err) bs := NewBlockStore(dbm.NewMemDB()) - b1 := state.MakeBlock(state.LastBlockHeight+1, test.MakeNTxs(state.LastBlockHeight+1, 10), nil, new(types.Commit), nil, state.Validators.GetProposer().Address, nil) // TODO + b1 := state.MakeBlock(state.LastBlockHeight+1, test.MakeNTxs(state.LastBlockHeight+1, 10), nil, new(types.Commit), nil, state.Validators.GetProposer().Address) partSet, err := b1.MakePartSet(2) require.NoError(t, err) seenCommit := makeTestCommit(1, tmtime.Now()) @@ -579,7 +579,7 @@ func TestBlockFetchAtHeight(t *testing.T) { state, bs, cleanup := makeStateAndBlockStore(log.NewTMLogger(new(bytes.Buffer))) defer cleanup() require.Equal(t, bs.Height(), int64(0), "initially the height should be zero") - block := state.MakeBlock(bs.Height()+1, nil, nil, new(types.Commit), nil, state.Validators.GetProposer().Address, nil) // TODO + block := state.MakeBlock(bs.Height()+1, nil, nil, new(types.Commit), nil, state.Validators.GetProposer().Address) partSet, err := block.MakePartSet(2) require.NoError(t, err) diff --git a/test/e2e/node/main.go b/test/e2e/node/main.go index f23417b3fb5..84ba5435c7b 100644 --- a/test/e2e/node/main.go +++ b/test/e2e/node/main.go @@ -13,7 +13,6 @@ import ( "github.com/spf13/viper" "github.com/tendermint/tendermint/abci/server" - "github.com/tendermint/tendermint/blssignatures" "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/crypto/ed25519" tmflags "github.com/tendermint/tendermint/libs/cli/flags" @@ -124,22 +123,18 @@ func startNode(cfg *Config) error { return fmt.Errorf("failed to setup config: %w", err) } - blsPrivKey, err := blssignatures.PrivateKeyFromBytes(blssignatures.LoadBLSKey(tmcfg.BLSKeyFile()).PrivKey) - if err != nil { - return fmt.Errorf("failed to load bls priv key") - } - n, err := node.NewNode( tmcfg, nil, // TODO privval.LoadOrGenFilePV(tmcfg.PrivValidatorKeyFile(), tmcfg.PrivValidatorStateFile()), - &blsPrivKey, nodeKey, proxy.NewLocalClientCreator(app), node.DefaultGenesisDocProviderFunc(tmcfg), node.DefaultDBProvider, node.DefaultMetricsProvider(tmcfg.Instrumentation), nodeLogger, + nil, + nil, ) if err != nil { return err diff --git a/types/params.go b/types/params.go index 6a6d000170c..92af7d67b52 100644 --- a/types/params.go +++ b/types/params.go @@ -32,22 +32,18 @@ var ABCIPubKeyTypesToNames = map[string]string{ // ConsensusParams contains consensus critical parameters that determine the // validity of blocks. +// +// The proto-level tmproto.BatchParams field is preserved on the wire for +// compatibility with historical state, but no Go-level field is exposed here: +// sequencer-side batch generation has been removed and tmproto.BatchParams is +// ignored by both Update and ConsensusParamsFromProto. type ConsensusParams struct { - Batch BatchParams `json:"batch"` Block BlockParams `json:"block"` Evidence EvidenceParams `json:"evidence"` Validator ValidatorParams `json:"validator"` Version VersionParams `json:"version"` } -// BatchParams define when to generate batch -type BatchParams struct { - BlocksInterval int64 `json:"blocks_interval"` - MaxBytes int64 `json:"max_bytes"` - Timeout time.Duration `json:"timeout"` - MaxChunks int64 `json:"max_chunks"` -} - // BlockParams define limits on the block size and gas plus minimum time // between blocks. type BlockParams struct { @@ -75,7 +71,6 @@ type VersionParams struct { // DefaultConsensusParams returns a default ConsensusParams. func DefaultConsensusParams() *ConsensusParams { return &ConsensusParams{ - Batch: DefaultBatchParams(), Block: DefaultBlockParams(), Evidence: DefaultEvidenceParams(), Validator: DefaultValidatorParams(), @@ -83,15 +78,6 @@ func DefaultConsensusParams() *ConsensusParams { } } -func DefaultBatchParams() BatchParams { - return BatchParams{ - BlocksInterval: 10, - MaxBytes: 8388608, - Timeout: 60 * time.Second, - MaxChunks: 15, - } -} - // DefaultBlockParams returns a default BlockParams. func DefaultBlockParams() BlockParams { return BlockParams{ @@ -187,26 +173,6 @@ func (params ConsensusParams) ValidateBasic() error { return errors.New("len(Validator.PubKeyTypes) must be greater than 0") } - if params.Batch.BlocksInterval < 0 { - return errors.New("blocks_interval can't be negative") - } - - if params.Batch.MaxBytes < 0 { - return errors.New("max_bytes can't be negative") - } - - if params.Batch.Timeout < 0 { - return errors.New("timeout can't be negative") - } - - if params.Batch.MaxChunks < 0 { - return errors.New("max_chunks can't be negative") - } - - if params.Batch.BlocksInterval <= 0 && params.Batch.MaxBytes <= 0 && params.Batch.Timeout <= 0 && params.Batch.MaxChunks <= 0 { - return errors.New("blocks_interval, max_bytes, timeout and max_chunks can't be all 0") - } - // Check if keyType is a known ABCIPubKeyType for i := 0; i < len(params.Validator.PubKeyTypes); i++ { keyType := params.Validator.PubKeyTypes[i] @@ -254,13 +220,8 @@ func (params ConsensusParams) Update(params2 *tmproto.ConsensusParams) Consensus return res } - // we must defensively consider any structs may be nil - if params2.Batch != nil { - res.Batch.BlocksInterval = params2.Batch.BlocksInterval - res.Batch.MaxBytes = params2.Batch.MaxBytes - res.Batch.Timeout = params2.Batch.Timeout - res.Batch.MaxChunks = params2.Batch.MaxChunks - } + // proto-level params2.Batch is intentionally ignored: sequencer batch + // generation is removed and the proto field exists only for wire compat. if params2.Block != nil { res.Block.MaxBytes = params2.Block.MaxBytes res.Block.MaxGas = params2.Block.MaxGas @@ -284,12 +245,6 @@ func (params ConsensusParams) Update(params2 *tmproto.ConsensusParams) Consensus func (params *ConsensusParams) ToProto() tmproto.ConsensusParams { return tmproto.ConsensusParams{ - Batch: &tmproto.BatchParams{ - BlocksInterval: params.Batch.BlocksInterval, - MaxBytes: params.Batch.MaxBytes, - Timeout: params.Batch.Timeout, - MaxChunks: params.Batch.MaxChunks, - }, Block: &tmproto.BlockParams{ MaxBytes: params.Block.MaxBytes, MaxGas: params.Block.MaxGas, @@ -309,13 +264,8 @@ func (params *ConsensusParams) ToProto() tmproto.ConsensusParams { } func ConsensusParamsFromProto(pbParams tmproto.ConsensusParams) ConsensusParams { + // proto-level pbParams.Batch is intentionally ignored; see ConsensusParams docs. return ConsensusParams{ - Batch: BatchParams{ - BlocksInterval: pbParams.Batch.BlocksInterval, - MaxBytes: pbParams.Batch.MaxBytes, - Timeout: pbParams.Batch.Timeout, - MaxChunks: pbParams.Batch.MaxChunks, - }, Block: BlockParams{ MaxBytes: pbParams.Block.MaxBytes, MaxGas: pbParams.Block.MaxGas,