Skip to content

Commit

Permalink
Merge branch 'development' into EN-6833/Antiflood-observers
Browse files Browse the repository at this point in the history
# Conflicts:
#	process/throttle/antiflood/p2pAntiflood.go
  • Loading branch information
sasurobert committed Jun 25, 2020
2 parents 377b38c + cab5a0c commit 3377cfe
Show file tree
Hide file tree
Showing 97 changed files with 1,002 additions and 725 deletions.
2 changes: 1 addition & 1 deletion cmd/node/config/economics.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
TotalSupply = "20000000000000000000000000000" #20BILERD
MinimumInflation = 0.0
MaximumInflation = 0.075 #fraction of value 1 - 7.5%
Denomination = 18 # represents the smallest erd subdivision (10^-X ERD for a denomination of X)

[RewardsSettings]
LeaderPercentage = 0.1 #fraction of value 1 - 10%
DeveloperPercentage = 0.3 #fraction of value 1 - 30%
CommunityPercentage = 0.1 #fraction of value 0.1 - 10%
CommunityAddress = "erd1932eft30w753xyvme8d49qejgkjc09n5e49w4mwdjtm0neld797su0dlxp"
DenominationCoefficientForView = "0.000000000000000001" #10^-18

[FeeSettings]
MaxGasLimitPerBlock = "1500000000"
Expand Down
12 changes: 6 additions & 6 deletions cmd/node/factory/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ type Process struct {
EpochStartTrigger epochStart.TriggerHandler
ForkDetector process.ForkDetector
BlockProcessor process.BlockProcessor
BlackListHandler process.BlackListHandler
BlackListHandler process.TimeCacher
BootStorer process.BootStorer
HeaderSigVerifier HeaderSigVerifierHandler
HeaderIntegrityVerifier HeaderIntegrityVerifierHandler
Expand Down Expand Up @@ -646,7 +646,7 @@ func newInterceptorContainerFactory(
epochStartTrigger process.EpochStartTriggerHandler,
whiteListHandler process.WhiteListHandler,
whiteListerVerifiedTxs process.WhiteListHandler,
) (process.InterceptorsContainerFactory, process.BlackListHandler, error) {
) (process.InterceptorsContainerFactory, process.TimeCacher, error) {
if shardCoordinator.SelfId() < shardCoordinator.NumberOfShards() {
return newShardInterceptorContainerFactory(
shardCoordinator,
Expand Down Expand Up @@ -741,7 +741,7 @@ func newShardInterceptorContainerFactory(
epochStartTrigger process.EpochStartTriggerHandler,
whiteListHandler process.WhiteListHandler,
whiteListerVerifiedTxs process.WhiteListHandler,
) (process.InterceptorsContainerFactory, process.BlackListHandler, error) {
) (process.InterceptorsContainerFactory, process.TimeCacher, error) {
headerBlackList := timecache.NewTimeCache(timeSpanForBadHeaders)
shardInterceptorsContainerFactoryArgs := interceptorscontainer.ShardInterceptorsContainerFactoryArgs{
Accounts: state.AccountsAdapter,
Expand All @@ -761,7 +761,7 @@ func newShardInterceptorContainerFactory(
AddressPubkeyConverter: state.AddressPubkeyConverter,
MaxTxNonceDeltaAllowed: core.MaxTxNonceDeltaAllowed,
TxFeeHandler: economics,
BlackList: headerBlackList,
BlockBlackList: headerBlackList,
HeaderSigVerifier: headerSigVerifier,
HeaderIntegrityVerifier: headerIntegrityVerifier,
SizeCheckDelta: sizeCheckDelta,
Expand Down Expand Up @@ -796,7 +796,7 @@ func newMetaInterceptorContainerFactory(
epochStartTrigger process.EpochStartTriggerHandler,
whiteListHandler process.WhiteListHandler,
whiteListerVerifiedTxs process.WhiteListHandler,
) (process.InterceptorsContainerFactory, process.BlackListHandler, error) {
) (process.InterceptorsContainerFactory, process.TimeCacher, error) {
headerBlackList := timecache.NewTimeCache(timeSpanForBadHeaders)
metaInterceptorsContainerFactoryArgs := interceptorscontainer.MetaInterceptorsContainerFactoryArgs{
ShardCoordinator: shardCoordinator,
Expand Down Expand Up @@ -997,7 +997,7 @@ func newBlockTracker(
func newForkDetector(
rounder consensus.Rounder,
shardCoordinator sharding.Coordinator,
headerBlackList process.BlackListHandler,
headerBlackList process.TimeCacher,
blockTracker process.BlockTracker,
genesisTime int64,
) (process.ForkDetector, error) {
Expand Down
32 changes: 29 additions & 3 deletions cmd/node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import (
"github.com/ElrondNetwork/elrond-go/process/smartContract"
"github.com/ElrondNetwork/elrond-go/process/smartContract/builtInFunctions"
"github.com/ElrondNetwork/elrond-go/process/smartContract/hooks"
"github.com/ElrondNetwork/elrond-go/process/throttle/antiflood/blackList"
"github.com/ElrondNetwork/elrond-go/process/transaction"
"github.com/ElrondNetwork/elrond-go/sharding"
"github.com/ElrondNetwork/elrond-go/storage"
Expand All @@ -77,6 +78,7 @@ import (
"github.com/ElrondNetwork/elrond-go/update/trigger"
"github.com/ElrondNetwork/elrond-go/vm"
vmcommon "github.com/ElrondNetwork/elrond-vm-common"
"github.com/denisbrodbeck/machineid"
"github.com/google/gops/agent"
"github.com/urfave/cli"
)
Expand All @@ -92,6 +94,7 @@ const (
secondsToWaitForP2PBootstrap = 20
maxNumGoRoutinesTxsByHashApi = 10
maxTimeToClose = 10 * time.Second
maxMachineIDLen = 10
)

var (
Expand Down Expand Up @@ -395,7 +398,16 @@ func main() {
app := cli.NewApp()
cli.AppHelpTemplate = nodeHelpTemplate
app.Name = "Elrond Node CLI App"
app.Version = fmt.Sprintf("%s/%s/%s-%s", appVersion, runtime.Version(), runtime.GOOS, runtime.GOARCH)
machineID, err := machineid.ProtectedID(app.Name)
if err != nil {
log.Warn("error fetching machine id", "error", err)
machineID = "unknown"
}
if len(machineID) > maxMachineIDLen {
machineID = machineID[:maxMachineIDLen]
}

app.Version = fmt.Sprintf("%s/%s/%s-%s/%s", appVersion, runtime.Version(), runtime.GOOS, runtime.GOARCH, machineID)
app.Usage = "This is the entry point for starting a new Elrond node - the app will start after the genesis timestamp"
app.Flags = []cli.Flag{
genesisFile,
Expand Down Expand Up @@ -447,7 +459,7 @@ func main() {
return startNode(c, log, app.Version)
}

err := app.Run(os.Args)
err = app.Run(os.Args)
if err != nil {
log.Error(err.Error())
os.Exit(1)
Expand Down Expand Up @@ -2079,6 +2091,20 @@ func createNode(
return nil, err
}

peerDenialEvaluator, err := blackList.NewPeerDenialEvaluator(
network.PeerBlackListHandler,
network.PkTimeCache,
networkShardingCollector,
)
if err != nil {
return nil, err
}

err = network.NetMessenger.SetPeerDenialEvaluator(peerDenialEvaluator)
if err != nil {
return nil, err
}

var nd *node.Node
nd, err = node.NewNode(
node.WithMessenger(network.NetMessenger),
Expand Down Expand Up @@ -2119,7 +2145,7 @@ func createNode(
node.WithEpochStartTrigger(process.EpochStartTrigger),
node.WithEpochStartEventNotifier(epochStartRegistrationHandler),
node.WithBlockBlackListHandler(process.BlackListHandler),
node.WithPeerBlackListHandler(network.PeerBlackListHandler),
node.WithPeerDenialEvaluator(peerDenialEvaluator),
node.WithNetworkShardingCollector(networkShardingCollector),
node.WithBootStorer(process.BootStorer),
node.WithRequestedItemsHandler(requestedItemsHandler),
Expand Down
2 changes: 1 addition & 1 deletion cmd/node/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func InitMetrics(
appStatusHandler.SetUInt64Value(core.MetricRoundsPassedInCurrentEpoch, initUint)
appStatusHandler.SetUInt64Value(core.MetricNoncesPassedInCurrentEpoch, initUint)
appStatusHandler.SetStringValue(core.MetricLeaderPercentage, fmt.Sprintf("%f", economicsConfig.RewardsSettings.LeaderPercentage))
appStatusHandler.SetStringValue(core.MetricDenominationCoefficient, economicsConfig.RewardsSettings.DenominationCoefficientForView)
appStatusHandler.SetUInt64Value(core.MetricDenomination, uint64(economicsConfig.GlobalSettings.Denomination))
appStatusHandler.SetUInt64Value(core.MetricNumConnectedPeers, initUint)
appStatusHandler.SetStringValue(core.MetricNumConnectedPeersClassification, initString)
appStatusHandler.SetStringValue(core.MetricLatestTagSoftwareVersion, initString)
Expand Down
10 changes: 5 additions & 5 deletions config/economicsConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ type GlobalSettings struct {
TotalSupply string
MinimumInflation float64
MaximumInflation float64
Denomination int
}

// RewardsSettings will hold economics rewards settings
type RewardsSettings struct {
LeaderPercentage float64
DeveloperPercentage float64
CommunityPercentage float64
CommunityAddress string
DenominationCoefficientForView string
LeaderPercentage float64
DeveloperPercentage float64
CommunityPercentage float64
CommunityAddress string
}

// FeeSettings will hold economics fee settings
Expand Down
17 changes: 10 additions & 7 deletions config/tomlConfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,17 @@ func TestTomlEconomicsParser(t *testing.T) {
minGasPrice := "18446744073709551615"
minGasLimit := "18446744073709551615"
communityAddress := "erd1932eft30w753xyvme8d49qejgkjc09n5e49w4mwdjtm0neld797su0dlxp"
denominatinoCoefficient := "0.000000000000000001"
denomination := 18

cfgEconomicsExpected := EconomicsConfig{
GlobalSettings: GlobalSettings{
Denomination: denomination,
},
RewardsSettings: RewardsSettings{
LeaderPercentage: leaderPercentage,
CommunityPercentage: communityPercentage,
CommunityAddress: communityAddress,
DenominationCoefficientForView: denominatinoCoefficient,
DeveloperPercentage: developerPercentage,
LeaderPercentage: leaderPercentage,
CommunityPercentage: communityPercentage,
CommunityAddress: communityAddress,
DeveloperPercentage: developerPercentage,
},
FeeSettings: FeeSettings{
MaxGasLimitPerBlock: maxGasLimitPerBlock,
Expand All @@ -140,10 +142,11 @@ func TestTomlEconomicsParser(t *testing.T) {
}

testString := `
[GlobalSettings]
Denomination = ` + fmt.Sprintf("%d", denomination) + `
[RewardsSettings]
CommunityPercentage = ` + fmt.Sprintf("%.6f", communityPercentage) + `
CommunityAddress = "` + communityAddress + `"
DenominationCoefficientForView = "` + denominatinoCoefficient + `"
LeaderPercentage = ` + fmt.Sprintf("%.6f", leaderPercentage) + `
DeveloperPercentage = ` + fmt.Sprintf("%.6f", developerPercentage) + `
[FeeSettings]
Expand Down
4 changes: 2 additions & 2 deletions core/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ const MetricPeerType = "erd_peer_type"
//MetricLeaderPercentage is the metric for leader rewards percentage
const MetricLeaderPercentage = "erd_leader_percentage"

//MetricDenominationCoefficient is the metric for denomination coefficient that is used in views
const MetricDenominationCoefficient = "erd_denomination_coefficient"
//MetricDenomination is the metric for exposing the denomination
const MetricDenomination = "erd_denomination"

// MetricRoundAtEpochStart is the metric for storing the first round of the current epoch
const MetricRoundAtEpochStart = "erd_round_at_epoch_start"
Expand Down
3 changes: 2 additions & 1 deletion factory/dtos.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,6 @@ type NetworkComponents struct {
NetMessenger p2p.Messenger
InputAntifloodHandler P2PAntifloodHandler
OutputAntifloodHandler P2PAntifloodHandler
PeerBlackListHandler process.PeerBlackListHandler
PeerBlackListHandler process.PeerBlackListCacher
PkTimeCache process.TimeCacher
}
14 changes: 6 additions & 8 deletions factory/networkComponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/ElrondNetwork/elrond-go/core/check"
"github.com/ElrondNetwork/elrond-go/debug/antiflood"
"github.com/ElrondNetwork/elrond-go/p2p/libp2p"
"github.com/ElrondNetwork/elrond-go/process"
antifloodFactory "github.com/ElrondNetwork/elrond-go/process/throttle/antiflood/factory"
storageFactory "github.com/ElrondNetwork/elrond-go/storage/factory"
"github.com/ElrondNetwork/elrond-go/storage/storageUnit"
Expand Down Expand Up @@ -50,7 +51,7 @@ func (ncf *networkComponentsFactory) Create() (*NetworkComponents, error) {
return nil, err
}

inAntifloodHandler, p2pPeerBlackList, errNewAntiflood := antifloodFactory.NewP2PAntiFloodAndBlackList(
inAntifloodHandler, peerIdBlackList, pkTimeCache, errNewAntiflood := antifloodFactory.NewP2PAntiFloodAndBlackList(
ncf.mainConfig,
ncf.statusHandler,
netMessenger.ID(),
Expand All @@ -60,7 +61,8 @@ func (ncf *networkComponentsFactory) Create() (*NetworkComponents, error) {
}

if ncf.mainConfig.Debug.Antiflood.Enabled {
debugger, err := antiflood.NewAntifloodDebugger(ncf.mainConfig.Debug.Antiflood)
var debugger process.AntifloodDebugger
debugger, err = antiflood.NewAntifloodDebugger(ncf.mainConfig.Debug.Antiflood)
if err != nil {
return nil, err
}
Expand All @@ -86,11 +88,6 @@ func (ncf *networkComponentsFactory) Create() (*NetworkComponents, error) {
return nil, fmt.Errorf("%w when casting output antiflood handler to structs/P2PAntifloodHandler", ErrWrongTypeAssertion)
}

err = netMessenger.SetPeerBlackListHandler(p2pPeerBlackList)
if err != nil {
return nil, err
}

cache, err := storageUnit.NewCache(storageFactory.GetCacherFromConfig(ncf.mainConfig.P2PMessageIDAdditionalCache))
if err != nil {
return nil, fmt.Errorf("%w while creating p2p cacher", err)
Expand All @@ -105,6 +102,7 @@ func (ncf *networkComponentsFactory) Create() (*NetworkComponents, error) {
NetMessenger: netMessenger,
InputAntifloodHandler: inputAntifloodHandler,
OutputAntifloodHandler: outputAntifloodHandler,
PeerBlackListHandler: p2pPeerBlackList,
PeerBlackListHandler: peerIdBlackList,
PkTimeCache: pkTimeCache,
}, nil
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/beevik/ntp v0.2.0
github.com/btcsuite/btcd v0.20.1-beta
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d
github.com/denisbrodbeck/machineid v1.0.1
github.com/elastic/go-elasticsearch/v7 v7.1.0
github.com/gin-contrib/cors v0.0.0-20190301062745-f9e10995c85a
github.com/gin-contrib/pprof v1.2.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ github.com/davidlazar/go-crypto v0.0.0-20170701192655-dcfb0a7ac018 h1:6xT9KW8zLC
github.com/davidlazar/go-crypto v0.0.0-20170701192655-dcfb0a7ac018/go.mod h1:rQYf4tfk5sSwFsnDg3qYaBxSjsD9S8+59vW0dKUgme4=
github.com/davidlazar/go-crypto v0.0.0-20190912175916-7055855a373f h1:BOaYiTvg8p9vBUXpklC22XSK/mifLF7lG9jtmYYi3Tc=
github.com/davidlazar/go-crypto v0.0.0-20190912175916-7055855a373f/go.mod h1:rQYf4tfk5sSwFsnDg3qYaBxSjsD9S8+59vW0dKUgme4=
github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ=
github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI=
github.com/dgraph-io/badger v1.5.5-0.20190226225317-8115aed38f8f/go.mod h1:VZxzAIRPHRVNRKRo6AXrX9BJegn6il06VMTZVJYCIjQ=
github.com/dgraph-io/badger v1.6.0-rc1/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhYy6psNgSztDR4=
github.com/dgraph-io/badger v1.6.0/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhYy6psNgSztDR4=
Expand Down
4 changes: 2 additions & 2 deletions integrationTests/consensus/testInitializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ func createConsensusOnlyNode(
node.WithDataStore(createTestStore()),
node.WithResolversFinder(resolverFinder),
node.WithConsensusType(consensusType),
node.WithBlockBlackListHandler(&mock.BlackListHandlerStub{}),
node.WithPeerBlackListHandler(&mock.PeerBlackListHandlerStub{}),
node.WithBlockBlackListHandler(&mock.TimeCacheStub{}),
node.WithPeerDenialEvaluator(&mock.PeerDenialEvaluatorStub{}),
node.WithEpochStartTrigger(epochStartTrigger),
node.WithEpochStartEventNotifier(epochStartRegistrationHandler),
node.WithNetworkShardingCollector(mock.NewNetworkShardingCollectorMock()),
Expand Down
16 changes: 12 additions & 4 deletions integrationTests/longTests/antiflooding/antiflooding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/ElrondNetwork/elrond-go/integrationTests/mock"
"github.com/ElrondNetwork/elrond-go/p2p"
"github.com/ElrondNetwork/elrond-go/process"
"github.com/ElrondNetwork/elrond-go/process/throttle/antiflood/blackList"
"github.com/ElrondNetwork/elrond-go/process/throttle/antiflood/factory"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -114,11 +115,12 @@ func createProcessors(peers []p2p.Messenger, topic string, idxBadPeers []int, id
processors := make([]*messageProcessor, 0, len(peers))
for i := 0; i < len(peers); i++ {
var antiflood process.P2PAntifloodHandler
var blackListHandler process.PeerBlackListHandler
var blackListHandler process.PeerBlackListCacher
var pkTimeCache process.TimeCacher
var err error

if intInSlice(i, idxBadPeers) {
antiflood, blackListHandler, err = factory.NewP2PAntiFloodAndBlackList(
antiflood, blackListHandler, pkTimeCache, err = factory.NewP2PAntiFloodAndBlackList(
createDisabledConfig(),
&mock.AppStatusHandlerStub{},
peers[i].ID(),
Expand All @@ -128,15 +130,21 @@ func createProcessors(peers []p2p.Messenger, topic string, idxBadPeers []int, id

if intInSlice(i, idxGoodPeers) {
statusHandler := &mock.AppStatusHandlerStub{}
antiflood, blackListHandler, err = factory.NewP2PAntiFloodAndBlackList(
antiflood, blackListHandler, pkTimeCache, err = factory.NewP2PAntiFloodAndBlackList(
createWorkableConfig(),
statusHandler,
peers[i].ID(),
)
log.LogIfError(err)
}

err = peers[i].SetPeerBlackListHandler(blackListHandler)
pde, _ := blackList.NewPeerDenialEvaluator(
blackListHandler,
pkTimeCache,
&mock.PeerShardMapperStub{},
)

err = peers[i].SetPeerDenialEvaluator(pde)
log.LogIfError(err)

proc := NewMessageProcessor(antiflood, peers[i])
Expand Down

0 comments on commit 3377cfe

Please sign in to comment.