Skip to content

Commit

Permalink
Merge branch 's3' into picks-for-s3
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo Chen authored Jan 13, 2020
2 parents b2210fa + 9b834c4 commit 129a56a
Show file tree
Hide file tree
Showing 15 changed files with 139 additions and 684 deletions.
2 changes: 1 addition & 1 deletion cmd/client/wallet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ var (
transferSenderPtr = transferCommand.String("from", "0", "Specify the sender account address or index")
transferReceiverPtr = transferCommand.String("to", "", "Specify the receiver account")
transferAmountPtr = transferCommand.Float64("amount", 0, "Specify the amount to transfer")
transferGasPricePtr = transferCommand.Uint64("gasPrice", 0, "Specify the gas price amount. Unit is Nano.")
transferGasPricePtr = transferCommand.Uint64("gasPrice", 1, "Specify the gas price amount. Unit is Nano.")
transferShardIDPtr = transferCommand.Int("shardID", -1, "Specify the shard ID for the transfer")
transferToShardIDPtr = transferCommand.Int("toShardID", -1, "Specify the destination shard ID for the transfer")
transferInputDataPtr = transferCommand.String("inputData", "", "Base64-encoded input data to embed in the transaction")
Expand Down
3 changes: 3 additions & 0 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,7 @@ func (bc *BlockChain) InsertChain(chain types.Blocks) (int, error) {
n, events, logs, err := bc.insertChain(chain)
bc.PostChainEvents(events, logs)
if err == nil {
// TODO: incorporate these into insertChain (already done in master)
for idx, block := range chain {
header := block.Header()
header.Logger(utils.Logger()).Info().
Expand Down Expand Up @@ -1176,6 +1177,8 @@ func (bc *BlockChain) InsertChain(chain types.Blocks) (int, error) {
}
}

// This should be done after everything about adding a block is done.
bc.PostChainEvents(events, logs)
return n, err
}

Expand Down
13 changes: 6 additions & 7 deletions core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func (pool *TxPool) loop() {
defer journal.Stop()

// Track the previous head headers for transaction reorgs
//head := pool.chain.CurrentBlock()
head := pool.chain.CurrentBlock()

// Keep waiting for and reacting to the various events
for {
Expand All @@ -301,12 +301,11 @@ func (pool *TxPool) loop() {
case ev := <-pool.chainHeadCh:
if ev.Block != nil {
pool.mu.Lock()
//if pool.chainconfig.IsHomestead(ev.Block.Number()) {
// pool.homestead = true
//}
//pool.reset(head.Header(), ev.Block.Header())
//head = ev.Block

if pool.chainconfig.IsS3(ev.Block.Epoch()) {
pool.homestead = true
}
pool.reset(head.Header(), ev.Block.Header())
head = ev.Block
pool.mu.Unlock()
}
// Be unsubscribed due to system stopped
Expand Down
40 changes: 0 additions & 40 deletions internal/configs/sharding/fixedschedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package shardingconfig

import (
"math/big"
"time"

"github.com/harmony-one/harmony/common/denominations"
)

const (
Expand Down Expand Up @@ -55,43 +52,6 @@ func (s fixedSchedule) RandomnessStartingEpoch() uint64 {
return mainnetRandomnessStartingEpoch
}

func (s fixedSchedule) MaxTxAmountLimit() *big.Int {
amountBigInt := big.NewInt(mainnetMaxTxAmountLimit)
amountBigInt = amountBigInt.Mul(amountBigInt, big.NewInt(denominations.One))
return amountBigInt
}

func (s fixedSchedule) MaxNumRecentTxsPerAccountLimit() uint64 {
return mainnetMaxNumRecentTxsPerAccountLimit
}

func (s fixedSchedule) MaxTxPoolSizeLimit() int {
return mainnetMaxTxPoolSizeLimit
}

func (s fixedSchedule) MaxNumTxsPerBlockLimit() int {
return mainnetMaxNumTxsPerBlockLimit
}

func (s fixedSchedule) RecentTxDuration() time.Duration {
return mainnetRecentTxDuration
}

func (s fixedSchedule) EnableTxnThrottling() bool {
return mainnetEnableTxnThrottling
}

func (s fixedSchedule) TxsThrottleConfig() *TxsThrottleConfig {
return &TxsThrottleConfig{
MaxTxAmountLimit: s.MaxTxAmountLimit(),
MaxNumRecentTxsPerAccountLimit: s.MaxNumRecentTxsPerAccountLimit(),
MaxTxPoolSizeLimit: s.MaxTxPoolSizeLimit(),
MaxNumTxsPerBlockLimit: s.MaxNumTxsPerBlockLimit(),
RecentTxDuration: s.RecentTxDuration(),
EnableTxnThrottling: s.EnableTxnThrottling(),
}
}

func (s fixedSchedule) GetNetworkID() NetworkID {
return DevNet
}
Expand Down
46 changes: 0 additions & 46 deletions internal/configs/sharding/localnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package shardingconfig
import (
"fmt"
"math/big"
"time"

"github.com/harmony-one/harmony/common/denominations"
"github.com/harmony-one/harmony/internal/genesis"
)

Expand All @@ -26,13 +24,6 @@ const (
localnetConsensusRatio = float64(0.1)

localnetRandomnessStartingEpoch = 0

localnetMaxTxAmountLimit = 1e3 // unit is in One
localnetMaxNumRecentTxsPerAccountLimit = 1e2
localnetMaxTxPoolSizeLimit = 8000
localnetMaxNumTxsPerBlockLimit = 1000
localnetRecentTxDuration = time.Hour
localnetEnableTxnThrottling = false
)

func (localnetSchedule) InstanceForEpoch(epoch *big.Int) Instance {
Expand Down Expand Up @@ -97,43 +88,6 @@ func (ls localnetSchedule) RandomnessStartingEpoch() uint64 {
return localnetRandomnessStartingEpoch
}

func (ls localnetSchedule) MaxTxAmountLimit() *big.Int {
amountBigInt := big.NewInt(localnetMaxTxAmountLimit)
amountBigInt = amountBigInt.Mul(amountBigInt, big.NewInt(denominations.One))
return amountBigInt
}

func (ls localnetSchedule) MaxNumRecentTxsPerAccountLimit() uint64 {
return localnetMaxNumRecentTxsPerAccountLimit
}

func (ls localnetSchedule) MaxTxPoolSizeLimit() int {
return localnetMaxTxPoolSizeLimit
}

func (ls localnetSchedule) MaxNumTxsPerBlockLimit() int {
return localnetMaxNumTxsPerBlockLimit
}

func (ls localnetSchedule) RecentTxDuration() time.Duration {
return localnetRecentTxDuration
}

func (ls localnetSchedule) EnableTxnThrottling() bool {
return localnetEnableTxnThrottling
}

func (ls localnetSchedule) TxsThrottleConfig() *TxsThrottleConfig {
return &TxsThrottleConfig{
MaxTxAmountLimit: ls.MaxTxAmountLimit(),
MaxNumRecentTxsPerAccountLimit: ls.MaxNumRecentTxsPerAccountLimit(),
MaxTxPoolSizeLimit: ls.MaxTxPoolSizeLimit(),
MaxNumTxsPerBlockLimit: ls.MaxNumTxsPerBlockLimit(),
RecentTxDuration: ls.RecentTxDuration(),
EnableTxnThrottling: ls.EnableTxnThrottling(),
}
}

func (ls localnetSchedule) GetNetworkID() NetworkID {
return LocalNet
}
Expand Down
46 changes: 0 additions & 46 deletions internal/configs/sharding/mainnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package shardingconfig

import (
"math/big"
"time"

"github.com/harmony-one/harmony/common/denominations"
"github.com/harmony-one/harmony/internal/genesis"
)

Expand All @@ -29,13 +27,6 @@ const (
mainnetV1_4Epoch = 46
mainnetV1_5Epoch = 54

mainnetMaxTxAmountLimit = 1e3 // unit is interface{} One
mainnetMaxNumRecentTxsPerAccountLimit = 1e2
mainnetMaxTxPoolSizeLimit = 8000
mainnetMaxNumTxsPerBlockLimit = 1000
mainnetRecentTxDuration = time.Hour
mainnetEnableTxnThrottling = false

// MainNetHTTPPattern is the http pattern for mainnet.
MainNetHTTPPattern = "https://api.s%d.t.hmny.io"
// MainNetWSPattern is the websocket pattern for mainnet.
Expand Down Expand Up @@ -135,43 +126,6 @@ func (ms mainnetSchedule) RandomnessStartingEpoch() uint64 {
return mainnetRandomnessStartingEpoch
}

func (ms mainnetSchedule) MaxTxAmountLimit() *big.Int {
amountBigInt := big.NewInt(mainnetMaxTxAmountLimit)
amountBigInt = amountBigInt.Mul(amountBigInt, big.NewInt(denominations.One))
return amountBigInt
}

func (ms mainnetSchedule) MaxNumRecentTxsPerAccountLimit() uint64 {
return mainnetMaxNumRecentTxsPerAccountLimit
}

func (ms mainnetSchedule) MaxTxPoolSizeLimit() int {
return mainnetMaxTxPoolSizeLimit
}

func (ms mainnetSchedule) MaxNumTxsPerBlockLimit() int {
return mainnetMaxNumTxsPerBlockLimit
}

func (ms mainnetSchedule) RecentTxDuration() time.Duration {
return mainnetRecentTxDuration
}

func (ms mainnetSchedule) EnableTxnThrottling() bool {
return mainnetEnableTxnThrottling
}

func (ms mainnetSchedule) TxsThrottleConfig() *TxsThrottleConfig {
return &TxsThrottleConfig{
MaxTxAmountLimit: ms.MaxTxAmountLimit(),
MaxNumRecentTxsPerAccountLimit: ms.MaxNumRecentTxsPerAccountLimit(),
MaxTxPoolSizeLimit: ms.MaxTxPoolSizeLimit(),
MaxNumTxsPerBlockLimit: ms.MaxNumTxsPerBlockLimit(),
RecentTxDuration: ms.RecentTxDuration(),
EnableTxnThrottling: ms.EnableTxnThrottling(),
}
}

func (ms mainnetSchedule) GetNetworkID() NetworkID {
return MainNet
}
Expand Down
42 changes: 0 additions & 42 deletions internal/configs/sharding/pangaea.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ package shardingconfig

import (
"math/big"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/harmony-one/harmony/common/denominations"

"github.com/harmony-one/harmony/internal/genesis"
)

Expand All @@ -15,8 +12,6 @@ const (
PangaeaHTTPPattern = "https://api.s%d.pga.hmny.io"
// PangaeaWSPattern is the websocket pattern for pangaea.
PangaeaWSPattern = "wss://ws.s%d.pga.hmny.io"
// transaction throttling disabled on pangaea network
pangaeaEnableTxnThrottling = false
)

// PangaeaSchedule is the Pangaea sharding configuration schedule.
Expand Down Expand Up @@ -64,43 +59,6 @@ func (ps pangaeaSchedule) RandomnessStartingEpoch() uint64 {
return mainnetRandomnessStartingEpoch
}

func (ps pangaeaSchedule) MaxTxAmountLimit() *big.Int {
amountBigInt := big.NewInt(mainnetMaxTxAmountLimit)
amountBigInt = amountBigInt.Mul(amountBigInt, big.NewInt(denominations.One))
return amountBigInt
}

func (ps pangaeaSchedule) MaxNumRecentTxsPerAccountLimit() uint64 {
return mainnetMaxNumRecentTxsPerAccountLimit
}

func (ps pangaeaSchedule) MaxTxPoolSizeLimit() int {
return mainnetMaxTxPoolSizeLimit
}

func (ps pangaeaSchedule) MaxNumTxsPerBlockLimit() int {
return mainnetMaxNumTxsPerBlockLimit
}

func (ps pangaeaSchedule) RecentTxDuration() time.Duration {
return mainnetRecentTxDuration
}

func (ps pangaeaSchedule) EnableTxnThrottling() bool {
return pangaeaEnableTxnThrottling
}

func (ps pangaeaSchedule) TxsThrottleConfig() *TxsThrottleConfig {
return &TxsThrottleConfig{
MaxTxAmountLimit: ps.MaxTxAmountLimit(),
MaxNumRecentTxsPerAccountLimit: ps.MaxNumRecentTxsPerAccountLimit(),
MaxTxPoolSizeLimit: ps.MaxTxPoolSizeLimit(),
MaxNumTxsPerBlockLimit: ps.MaxNumTxsPerBlockLimit(),
RecentTxDuration: ps.RecentTxDuration(),
EnableTxnThrottling: ps.EnableTxnThrottling(),
}
}

func (pangaeaSchedule) GetNetworkID() NetworkID {
return Pangaea
}
Expand Down
67 changes: 0 additions & 67 deletions internal/configs/sharding/shardingconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package shardingconfig
import (
"fmt"
"math/big"
"time"

"github.com/harmony-one/harmony/internal/genesis"
)
Expand Down Expand Up @@ -37,27 +36,6 @@ type Schedule interface {
//RandomnessStartingEpoch returns starting epoch of randonness generation
RandomnessStartingEpoch() uint64

// Max amount limit for a valid transaction
MaxTxAmountLimit() *big.Int

// Max number of transactions of a particular account per block level
MaxNumRecentTxsPerAccountLimit() uint64

// Max total number of transactions allowed as pending transactions in transaction pool
MaxTxPoolSizeLimit() int

// Max total number of transactions allowed to be processed per block
MaxNumTxsPerBlockLimit() int

// How long "recent" means for transaction in time Duration unit
RecentTxDuration() time.Duration

// EnableTxnThrottling is the switch for transaction throttling
EnableTxnThrottling() bool

// configuration for throttling pending transactions
TxsThrottleConfig() *TxsThrottleConfig

// GetNetworkID() return networkID type.
GetNetworkID() NetworkID

Expand Down Expand Up @@ -90,51 +68,6 @@ type Instance interface {
ReshardingEpoch() []*big.Int
}

// TxThrottleFlag is the throttling flag for each transaction
// Refer below enum declaration for more context.
type TxThrottleFlag int

// TxThrottleFlag is determined per transaction
// during the new block proposal and pending transactions throttling
const (
TxSelect TxThrottleFlag = iota
TxUnselect
TxInvalid
)

func (result TxThrottleFlag) String() string {
switch result {
case TxSelect:
return "TxSelect"
case TxUnselect:
return "TxUnselect"
case TxInvalid:
return "TxInvalid"
}
return "TxThrottleUnknown"
}

// TxsThrottleConfig contains configuration for throttling pending transactions per node block
type TxsThrottleConfig struct {
// Max amount limit for a valid transaction
MaxTxAmountLimit *big.Int

// Max number of transactions of a particular account for the past hour
RecentTxDuration time.Duration

// Max number of transactions of a particular account for the past hour
MaxNumRecentTxsPerAccountLimit uint64

// Max total number of transactions allowed as pending transactions in transaction pool
MaxTxPoolSizeLimit int

// Max total number of transactions allowed to be processed per block
MaxNumTxsPerBlockLimit int

// EnableTxnThrottling is the switch for transaction throttling
EnableTxnThrottling bool
}

// genShardingStructure return sharding structure, given shard number and its patterns.
func genShardingStructure(shardNum, shardID int, httpPattern, wsPattern string) []map[string]interface{} {
res := []map[string]interface{}{}
Expand Down
Loading

0 comments on commit 129a56a

Please sign in to comment.