diff --git a/bls/bls.go b/bls/bls.go index 3d2ccc1..3aceb5c 100644 --- a/bls/bls.go +++ b/bls/bls.go @@ -20,7 +20,7 @@ import ( "crypto/rand" "errors" "fmt" - "github.com/phoreproject/bls/g2pubs" + "github.com/youchainhq/bls/g2pubs" "log" ) diff --git a/bls/keys_bls12_381.go b/bls/keys_bls12_381.go index 1e8ab9d..940d35a 100644 --- a/bls/keys_bls12_381.go +++ b/bls/keys_bls12_381.go @@ -18,7 +18,7 @@ package bls import ( "errors" - "github.com/phoreproject/bls/g2pubs" + "github.com/youchainhq/bls/g2pubs" ) var ErrSigMismatch = errors.New("signature mismatch") diff --git a/cmd/utils/flags_metrics.go b/cmd/utils/flags_metrics.go index 087912c..8b4568f 100644 --- a/cmd/utils/flags_metrics.go +++ b/cmd/utils/flags_metrics.go @@ -37,7 +37,7 @@ var ( cli.IntFlag{Name: "log.level", Value: int(logging.LvlInfo), Destination: &nodeCfg.LogLevel}, cli.StringFlag{Name: "log.vmodule", Destination: &nodeCfg.LogVmodule}, - cli.StringFlag{Name: "log.path", Destination: &nodeCfg.LogPath, Value: "logs"}, + cli.StringFlag{Name: "log.path", Destination: &nodeCfg.LogPath}, //use in metrics/metrics.go cli.BoolFlag{Name: "metrics", Destination: &nodeCfg.Metrics.Metrics}, diff --git a/consensus/ucon/consensus.go b/consensus/ucon/consensus.go index 385a0be..1ad53b0 100644 --- a/consensus/ucon/consensus.go +++ b/consensus/ucon/consensus.go @@ -51,10 +51,6 @@ var ( errInvalidSealer = errors.New("invalid sealer") ) -var ( - allowedFutureBlockTime = 15 * time.Second // Max time from current time allowed for blocks, before they're considered future blocks -) - func (s *Server) Author(header *types.Header) (common.Address, error) { return common.Address{}, nil } @@ -75,8 +71,13 @@ func (s *Server) verifyHeader(chain consensus.ChainReader, header *types.Header, return errUnknownBlock } + // get consensus parameters for round + yp, err := chain.VersionForRoundWithParents(header.Number.Uint64(), parents) + if err != nil { + return err + } // Don't waste time checking blocks from the future - if header.Time > uint64(time.Now().Add(allowedFutureBlockTime).Unix()) { + if header.Time > uint64(time.Now().Add(yp.AllowedFutureBlockTime).Unix()) { return consensus.ErrFutureBlock } @@ -90,7 +91,7 @@ func (s *Server) verifyHeader(chain consensus.ChainReader, header *types.Header, return err } - return s.verifyCascadingFields(chain, header, parents, seal) + return s.verifyCascadingFields(chain, header, parents, seal, yp) } func (s *Server) verifySignature(header *types.Header) error { @@ -118,7 +119,7 @@ func (s *Server) verifySignature(header *types.Header) error { // rather depend on a batch of previous headers. The caller may optionally pass // in a batch of parents (ascending order) to avoid looking those up from the // database. This is useful for concurrently verifying a batch of new headers. -func (s *Server) verifyCascadingFields(chain consensus.ChainReader, header *types.Header, parents []*types.Header, seal bool) error { +func (s *Server) verifyCascadingFields(chain consensus.ChainReader, header *types.Header, parents []*types.Header, seal bool, yp *params.YouParams) error { // The genesis block is the always valid dead-end number := header.Number.Uint64() if number == 0 { @@ -148,17 +149,13 @@ func (s *Server) verifyCascadingFields(chain consensus.ChainReader, header *type return consensus.ErrExistCanonical } if seal { - return s.verifyConsensusField(chain, header, parents) + return s.verifyConsensusField(chain, header, parents, yp) } return nil } -func (s *Server) verifyConsensusField(chain consensus.ChainReader, header *types.Header, parents []*types.Header) error { +func (s *Server) verifyConsensusField(chain consensus.ChainReader, header *types.Header, parents []*types.Header, yp *params.YouParams) error { - yp, err := chain.VersionForRoundWithParents(header.Number.Uint64(), parents) - if err != nil { - return err - } cp := &yp.CaravelParams seedHeader, err := s.getLookBackHeader(cp, chain, header.Number, params.LookBackSeed, parents) if err != nil { @@ -580,7 +577,11 @@ func (s *Server) VerifySeal(chain consensus.ChainReader, header *types.Header) e if err := s.verifySignature(header); err != nil { return err } - return s.verifyConsensusField(chain, header, nil) + yp, err := chain.VersionForRoundWithParents(header.Number.Uint64(), nil) + if err != nil { + return err + } + return s.verifyConsensusField(chain, header, nil, yp) } // VerifySideChainHeader checks whether a side chain block confirms to the consensus rules diff --git a/core/genesis.go b/core/genesis.go index bb703b3..f567475 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -343,7 +343,7 @@ func DefaultGenesisBlock() *Genesis { return &Genesis{ NetworkId: params.MainNetId, Consensus: hexutil.MustDecode("0xf84e8001a05d93025288dddb431e3f43e07c63d1a96a28bf033457c74ee3f4d8eed88d3cf601a0010000000000000000000000000000000000000000000000000000000000000001801a8207d0820fa0"), - GasLimit: 8888888, + GasLimit: 0x888888, Alloc: decodePrealloc(mainnetAllocData), Validators: decodeValidators(mainnetValidatorsData), CurrVersion: params.YouV1, diff --git a/core/genesis_test.go b/core/genesis_test.go index aefd37e..104f9db 100644 --- a/core/genesis_test.go +++ b/core/genesis_test.go @@ -299,7 +299,7 @@ func TestDefaultGenesisBlock(t *testing.T) { require.Greater(t, len(g.Validators), 0) db := youdb.NewMemDatabase() b := g.ToBlock(db) - gh := common.HexToHash("0xa8fdcf4a6b91c0e5937309c812bc77f38ff4ae16294c24ae0c654f5b6fdaeeeb") + gh := common.HexToHash("0xce0efc6c8bd2195b53bf9cce7e7fff3bfc8aeba19b1f314ab029da68a521acf6") if b.Hash() != gh { t.Fatal("DefaultGenesisBlock hash mismatch") } diff --git a/core/protocol_version_processor_test.go b/core/protocol_version_processor_test.go index 654d708..173c71c 100644 --- a/core/protocol_version_processor_test.go +++ b/core/protocol_version_processor_test.go @@ -36,7 +36,8 @@ func TestVerifyYouVersionState(t *testing.T) { wantNoError bool wantErr error } - yp, ok := params.Versions[params.YouCurrentVersion] + // SHOULD NOT use params.YouCurrentVersion here, because the test case only test V1 or V1 upgrade to V2 + yp, ok := params.Versions[params.YouV1] require.True(t, ok) tcs := []tcS{ diff --git a/go.mod b/go.mod index cda626b..c176662 100644 --- a/go.mod +++ b/go.mod @@ -25,13 +25,13 @@ require ( github.com/nanyan/golz4 v1.0.0 github.com/pborman/uuid v0.0.0-20180827223501-4c1ecd6722e8 github.com/peterh/liner v1.1.0 - github.com/phoreproject/bls v0.0.0-20191211001008-9d5f85bf4a9b github.com/rcrowley/go-metrics v0.0.0-20190826022208-cac0b30c2563 github.com/robertkrimen/otto v0.0.0-20180617131154-15f95af6e78d github.com/rs/cors v0.0.0-20180826180256-dc7332ab32be github.com/stretchr/testify v1.4.0 github.com/syndtr/goleveldb v1.0.0 github.com/urfave/cli v1.21.0 + github.com/youchainhq/bls v0.9.0 golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d golang.org/x/net v0.0.0-20200226121028-0de0cce0169b golang.org/x/sys v0.0.0-20190904154756-749cb33beabd diff --git a/go.sum b/go.sum index 7b7ff34..b7f7ee2 100644 --- a/go.sum +++ b/go.sum @@ -101,8 +101,6 @@ github.com/pborman/uuid v0.0.0-20180827223501-4c1ecd6722e8 h1:1ugHtU31mw8H2BNoNj github.com/pborman/uuid v0.0.0-20180827223501-4c1ecd6722e8/go.mod h1:VyrYX9gd7irzKovcSS6BIIEwPRkP2Wm2m9ufcdFSJ34= github.com/peterh/liner v1.1.0 h1:f+aAedNJA6uk7+6rXsYBnhdo4Xux7ESLe+kcuVUF5os= github.com/peterh/liner v1.1.0/go.mod h1:CRroGNssyjTd/qIG2FyxByd2S8JEAZXBl4qUrZf8GS0= -github.com/phoreproject/bls v0.0.0-20191211001008-9d5f85bf4a9b h1:tE/F54uL3jp0ZGSKNMPGCTF003pSmtD/sQojpKADAxY= -github.com/phoreproject/bls v0.0.0-20191211001008-9d5f85bf4a9b/go.mod h1:xHJKf2TLXUA39Dhv8k5QmQOxLsbrb1KeTS/3ERfLeqc= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rcrowley/go-metrics v0.0.0-20190826022208-cac0b30c2563 h1:dY6ETXrvDG7Sa4vE8ZQG4yqWg6UnOcbqTAahkV813vQ= @@ -121,6 +119,8 @@ github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpP github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/urfave/cli v1.21.0 h1:wYSSj06510qPIzGSua9ZqsncMmWE3Zr55KBERygyrxE= github.com/urfave/cli v1.21.0/go.mod h1:lxDj6qX9Q6lWQxIrbrT0nwecwUtRnhVZAJjJZrVUZZQ= +github.com/youchainhq/bls v0.9.0 h1:qM0uQu7nIBfQxn8eR+e5A+cQWOWsQfqJqPQZznXphcg= +github.com/youchainhq/bls v0.9.0/go.mod h1:IDYz3DRnRz/O11+C+Acp7D7yCxmUg6frH9JC6WKgpMg= golang.org/x/arch v0.0.0-20181203225421-5a4828bb7045/go.mod h1:cYlCBUl1MsqxdiKgmc4uh7TxZfWSFLOGSRR090WDxt8= golang.org/x/arch v0.0.0-20190312162104-788fe5ffcd8c/go.mod h1:flIaEI6LNU6xOCD5PaJvn9wGP0agmIOqjrtsKGRguv4= golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= diff --git a/internal/debug/log.go b/internal/debug/log.go index f919500..289ab69 100644 --- a/internal/debug/log.go +++ b/internal/debug/log.go @@ -18,11 +18,7 @@ package debug import ( - "github.com/mattn/go-colorable" - "github.com/mattn/go-isatty" "github.com/youchainhq/go-youchain/logging" - "io" - "os" ) func SetupLogger(printOrigin bool, level int, vmodule string, logDir string) error { @@ -36,20 +32,12 @@ func SetupLogger(printOrigin bool, level int, vmodule string, logDir string) err } if logDir != "" { - //terminal handler - usecolor := (isatty.IsTerminal(os.Stdout.Fd()) || isatty.IsCygwinTerminal(os.Stdout.Fd())) && os.Getenv("TERM") != "dumb" - output := io.Writer(os.Stdout) - if usecolor { - output = colorable.NewColorableStderr() - } - //setup file rotate handler config := logging.NewRotateConfig() config.LogDir = logDir - rfh := logging.NewFileRotateHandler(config, logging.TerminalFormat(usecolor)) + rfh := logging.NewFileRotateHandler(config, logging.TerminalFormat(false)) - ostream := logging.StreamHandler(output, logging.TerminalFormat(usecolor)) - logging.GRoot().SetHandler(logging.MultiHandler(ostream, rfh)) + logging.GRoot().SetHandler(rfh) } return nil diff --git a/internal/youapi/you_api.go b/internal/youapi/you_api.go index a8f4100..b5ad16c 100644 --- a/internal/youapi/you_api.go +++ b/internal/youapi/you_api.go @@ -384,6 +384,10 @@ func DoEstimateGas(ctx context.Context, c *Container, args CallArgs, blockNr rpc hi uint64 cap uint64 ) + if blockNr == rpc.PendingBlockNumber && !c.youChain.Miner().Mining() { + // only the working miner has pending block. if the miner is not working, change to the latest block. + blockNr = rpc.LatestBlockNumber + } logging.Info("DoEstimateGas", "height", blockNr.Int64(), "gasCap", gasCap) if args.Gas != nil && uint64(*args.Gas) >= params.TxGas { hi = uint64(*args.Gas) @@ -406,7 +410,7 @@ func DoEstimateGas(ctx context.Context, c *Container, args CallArgs, blockNr rpc executable := func(gas uint64) bool { args.Gas = (*hexutil.Uint64)(&gas) logging.Info("DoEstimateGas start doCall", "height", blockNr.Int64(), "gasCap", gasCap, "cap", cap) - _, _, failed, err := DoCall(ctx, c, args, rpc.PendingBlockNumber, vm.LocalConfig{}, 0, gasCap, false) + _, _, failed, err := DoCall(ctx, c, args, blockNr, vm.LocalConfig{}, 0, gasCap, false) if err != nil || failed { logging.Error("DoEstimateGas failed", "err", err, "failed", failed) return false diff --git a/miner/worker.go b/miner/worker.go index 651321c..a96c54d 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -279,17 +279,18 @@ func (w *worker) commitNewWork(interrupt *int32) { coinbase.SetBytes(w.engine.GetValMainAddress().Bytes()) parent := w.chain.CurrentBlock() + timestamp := uint64(time.Now().Unix()) - if uint64(time.Now().Unix()) <= parent.Time() { - log.Warn("local time is far behind") - return + if timestamp <= parent.Time() { + log.Warn("local time is far behind, use parent time plus one.") + timestamp = parent.Time() + 1 } num := parent.Number() header := &types.Header{ ParentHash: parent.Hash(), Number: num.Add(num, common.Big1()), - Time: uint64(time.Now().Unix()), + Time: timestamp, Coinbase: coinbase, GasLimit: core.CalcGasLimit(parent), GasRewards: big.NewInt(0), diff --git a/p2p/peer.go b/p2p/peer.go index 4aa446e..49e8fe5 100644 --- a/p2p/peer.go +++ b/p2p/peer.go @@ -127,9 +127,11 @@ type Peer struct { } // NewPeer returns a peer for testing purposes. -func NewPeer(id enode.ID, name string, caps []Cap) *Peer { +func NewPeer(id enode.ID, name string, caps []Cap, nodetype uint16) *Peer { //pipe, _ := net.Pipe() - node := enode.SignNull(new(enr.Record), id) + r := new(enr.Record) + r.Set(enr.NODETYPE(nodetype)) + node := enode.SignNull(r, id) conn := &conn{session: nil, transport: nil, node: node, caps: caps, name: name} peer := newPeer(conn, nil) close(peer.closed) // ensures Disconnect doesn't block diff --git a/params/all_versions.go b/params/all_versions.go index 2b9cafd..fe07d39 100644 --- a/params/all_versions.go +++ b/params/all_versions.go @@ -92,6 +92,8 @@ func mainNetProtocols() VersionsMap { SeedLookBack: 8, EnableBls: true, EnableInactivity: false, + + AllowedFutureBlockTime: 15 * time.Second, }, StakingParams: StakingParams{ RewardsPoolAddress: common.BigToAddress(big.NewInt(0x0000000000000000000000000000001111111111)), @@ -150,23 +152,28 @@ func mainNetProtocols() VersionsMap { MaxUpgradeWaitRounds: 15000, } + // v1 can updates to v2 + v2 := v1.DeepCopy() // copy first + // then update v1 + v1.ApprovedUpgradeVersion = YouV2 + // update the map value. + // then the previous `versionMap[v1.Version] = v1` can be deleted versionMap[v1.Version] = v1 - // when a new version need to be upgrade, the basic setting should be as follow: - /* - v2 := v1.DeepCopy() // copy first - // then update v1 - v1.ApprovedUpgradeVersion = YouV2 - // update the map value. - // then the previous `versionMap[v1.Version] = v1` can be deleted - versionMap[v1.Version] = v1 - - // change, set v2 values - v2.Version = YouV2 - Add or modify some params - v2.UpgradeWaitRounds = 12000 - versionMap[v2.Version] = v2 - */ + // change, set v2 values + v2.Version = YouV2 + //Add or modify some params + v2.AllowedFutureBlockTime = 10 * time.Second // use a smaller duration according to consensus time. + versionMap[v2.Version] = v2 + + // YouV3 adjust `SubsidyThreshold` and `UpgradeThreshold`, and tune txs-broadcast strategy + v3 := v2.DeepCopy() + v2.ApprovedUpgradeVersion = YouV3 + versionMap[v2.Version] = v2 + v3.SubsidyThreshold = 15 * YOU + v3.UpgradeThreshold = 8000 // will take effect on the next upgrade + v3.Version = YouV3 + versionMap[v3.Version] = v3 return versionMap } @@ -191,6 +198,8 @@ func testNetProtocols() VersionsMap { SeedLookBack: 8, EnableBls: true, EnableInactivity: false, + + AllowedFutureBlockTime: 15 * time.Second, }, StakingParams: StakingParams{ RewardsPoolAddress: common.BigToAddress(big.NewInt(0x0000000000000000000000000000001111111111)), @@ -249,23 +258,28 @@ func testNetProtocols() VersionsMap { MaxUpgradeWaitRounds: 15000, } - versionMap[YouV1] = v1 - - // when a new version need to be upgrade, the basic setting should be as follow: - /* - v2 := v1.DeepCopy() // copy first - // then update v1 - v1.ApprovedUpgradeVersion = YouV2 - // update the map value. - // then the previous `versionMap[v1.Version] = v1` can be deleted - versionMap[v1.Version] = v1 + // v1 can updates to v2 + v2 := v1.DeepCopy() // copy first + // then update v1 + v1.ApprovedUpgradeVersion = YouV2 + // update the map value. + // then the previous `versionMap[v1.Version] = v1` can be deleted + versionMap[v1.Version] = v1 - // change, set v2 values - v2.Version = YouV2 - Add or modify some params - v2.UpgradeWaitRounds = 12000 - versionMap[v2.Version] = v2 - */ + // change, set v2 values + v2.Version = YouV2 + //Add or modify some params + v2.AllowedFutureBlockTime = 10 * time.Second // use a smaller duration according to consensus time. + versionMap[v2.Version] = v2 + + // YouV3 adjust `SubsidyThreshold` and `UpgradeThreshold`, and tune txs-broadcast strategy + v3 := v2.DeepCopy() + v2.ApprovedUpgradeVersion = YouV3 + versionMap[v2.Version] = v2 + v3.SubsidyThreshold = 15 * YOU + v3.UpgradeThreshold = 8000 // will take effect on the next upgrade + v3.Version = YouV3 + versionMap[v3.Version] = v3 return versionMap } @@ -290,6 +304,8 @@ func protocolsForTestCase() VersionsMap { SeedLookBack: 8, EnableBls: true, EnableInactivity: false, + + AllowedFutureBlockTime: 15 * time.Second, }, StakingParams: StakingParams{ RewardsPoolAddress: common.BigToAddress(big.NewInt(0x0000000000000000000000000000001111111111)), @@ -348,7 +364,28 @@ func protocolsForTestCase() VersionsMap { MaxUpgradeWaitRounds: 1500, } - versionMap[YouV1] = v1 + // v1 can updates to v2 + v2 := v1.DeepCopy() // copy first + // then update v1 + v1.ApprovedUpgradeVersion = YouV2 + // update the map value. + // then the previous `versionMap[v1.Version] = v1` can be deleted + versionMap[v1.Version] = v1 + + // change, set v2 values + v2.Version = YouV2 + //Add or modify some params + v2.AllowedFutureBlockTime = 10 * time.Second // use a smaller duration according to consensus time. + versionMap[v2.Version] = v2 + + // YouV3 adjust `SubsidyThreshold` and `UpgradeThreshold`, and tune txs-broadcast strategy + v3 := v2.DeepCopy() + v2.ApprovedUpgradeVersion = YouV3 + versionMap[v2.Version] = v2 + v3.SubsidyThreshold = 15 * YOU + v3.UpgradeThreshold = 800 // will take effect on the next upgrade + v3.Version = YouV3 + versionMap[v3.Version] = v3 return versionMap } diff --git a/params/client_version.go b/params/client_version.go index 9efc4c2..e3ed29e 100644 --- a/params/client_version.go +++ b/params/client_version.go @@ -21,7 +21,7 @@ import "fmt" const ( VersionMajor = 0 // Major version component of the current release VersionMinor = 9 // Minor version component of the current release - VersionPatch = 5 // Patch version component of the current release + VersionPatch = 7 // Patch version component of the current release VersionMeta = "" // Version metadata to append to the version string. Set to "" for stable release. ) diff --git a/params/config.go b/params/config.go index 1e9b3f4..3dd9cb8 100644 --- a/params/config.go +++ b/params/config.go @@ -110,6 +110,8 @@ type CaravelParams struct { SeedLookBack uint64 EnableBls bool // enable bls signature. may be deprecated due to performance or security reason. EnableInactivity bool + // Max time from current time allowed for blocks, before they're considered future blocks + AllowedFutureBlockTime time.Duration } // StakingParams contains parameters of the staking module diff --git a/params/protocol_version.go b/params/protocol_version.go index 944feea..a7d5b84 100644 --- a/params/protocol_version.go +++ b/params/protocol_version.go @@ -22,6 +22,10 @@ type YouVersion uint64 const ( // YouV1 is a baseline version of the YOUChain consensus protocol. YouV1 = YouVersion(1) + // YouV2 adds the parameter `AllowedFutureBlockTime` + YouV2 = YouVersion(2) + // YouV3 adjust `SubsidyThreshold` and `UpgradeThreshold`, and tune txs-broadcast strategy + YouV3 = YouVersion(3) ) // !!! ********************* !!! @@ -30,4 +34,4 @@ const ( // YouCurrentVersion is the latest version and should be used // when a specific version is not provided. -const YouCurrentVersion = YouV1 +const YouCurrentVersion = YouV3 diff --git a/you/handler.go b/you/handler.go index 832b23e..8ee4968 100644 --- a/you/handler.go +++ b/you/handler.go @@ -250,9 +250,11 @@ func (pm *ProtocolManager) handle(p *peer, hook func()) error { pm.peerLifecycleFun(p, peerAdded) } - // Propagate existing transactions. new transactions appearing - // after this will be sent via broadcasts. - pm.syncTransactions(p) + if pnt == params.ArchiveNode || pnt == params.FullNode { + // Propagate existing transactions. new transactions appearing + // after this will be sent via broadcasts. + pm.syncTransactions(p) + } logging.Info("handshake accept new peer", "pid", p.id, "total", pm.peers.Len()) diff --git a/you/helper_test.go b/you/helper_test.go index b21dfe4..905bc31 100644 --- a/you/helper_test.go +++ b/you/helper_test.go @@ -146,7 +146,8 @@ func newTestPeer(t *testing.T, name string, version int, pm *ProtocolManager, sh var id enode.ID rand.Read(id[:]) - peer := pm.newPeer(version, p2p.NewPeer(id, name, nil), net) + nodetype := uint16(2) //fullnode + peer := pm.newPeer(version, p2p.NewPeer(id, name, nil, nodetype), net) // Start the peer on a new thread errc := make(chan error, 1) diff --git a/you/peer.go b/you/peer.go index c33243a..bf783de 100644 --- a/you/peer.go +++ b/you/peer.go @@ -26,6 +26,7 @@ import ( "github.com/youchainhq/go-youchain/crypto" "github.com/youchainhq/go-youchain/logging" "github.com/youchainhq/go-youchain/p2p" + "github.com/youchainhq/go-youchain/params" "github.com/youchainhq/go-youchain/rlp" "math/big" "sync" @@ -150,7 +151,7 @@ func (p *peer) broadcast() { if !ok { return } - if err := p.SendConsenuse(ev); err != nil { + if err := p.SendConsensus(ev); err != nil { return } case txs := <-p.queuedTxs: @@ -199,7 +200,7 @@ func (p *peer) SendTransactions(txs types.Transactions) error { return nil } -func (p *peer) SendConsenuse(ev *ucon.MessageEvent) error { +func (p *peer) SendConsensus(ev *ucon.MessageEvent) error { evb, err := rlp.EncodeToBytes(ev) if err != nil { return err @@ -551,13 +552,16 @@ func (ps *PeerSet) PeersWithoutBlock(hash common.Hash) []*peer { // PeersWithoutTx retrieves a list of peers that do not have a given transaction // in their set of known hashes. +// Only returns those peers whose node type is ArchiveNode or FullNode. func (ps *PeerSet) PeersWithoutTx(hash common.Hash) []*peer { ps.lock.RLock() defer ps.lock.RUnlock() list := make([]*peer, 0, len(ps.peers)) for _, p := range ps.peers { - if !p.knownTxs.Contains(hash) { + pnt := p.Node().Nodetype() + if (pnt == params.ArchiveNode || pnt == params.FullNode) && + !p.knownTxs.Contains(hash) { list = append(list, p) } } diff --git a/you/protocol_test.go b/you/protocol_test.go index 80486a3..c80f7f1 100644 --- a/you/protocol_test.go +++ b/you/protocol_test.go @@ -73,7 +73,8 @@ func testStatusMsgErrors(t *testing.T, protocol int) { for i, test := range tests { p, errc := newTestPeer(t, "peer", protocol, pm, false) - + ty := p.Node().Nodetype().String() + fmt.Println(ty) go p2p.Send(p.app, test.code, test.data) select {