Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adding sortition interval to the parameters #442

Merged
merged 1 commit into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion execution/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (exe *Execution) checkStamp(trx *tx.Tx, sb sandbox.Sandbox) error {
if trx.IsSubsidyTx() {
interval = 1
} else if trx.IsSortitionTx() {
interval = 7
interval = sb.Params().SortitionInterval
}

if !ok || curHeight-height > interval {
Expand Down
2 changes: 1 addition & 1 deletion types/genesis/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestGenesisTestNet(t *testing.T) {
assert.Equal(t, g.GenesisTime(), genTime)
assert.Equal(t, g.Params().BondInterval, uint32(120))

expected, _ := hash.FromString("b2c9af5adb7b0ff29b2ed2f16b6aa31f4aff090efdecb2bf4fb5d804a8f98351")
expected, _ := hash.FromString("e5e9479aaed9923b77c016548dd41741062d376fc1e98362b47458d49ddb5229")
assert.Equal(t, g.Hash(), expected)
}

Expand Down
10 changes: 6 additions & 4 deletions types/param/param.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ type Params struct {
TransactionToLiveInterval uint32 `cbor:"5,keyasint"`
BondInterval uint32 `cbor:"6,keyasint"`
UnbondInterval uint32 `cbor:"7,keyasint"`
FeeFraction float64 `cbor:"8,keyasint"`
MinimumFee int64 `cbor:"9,keyasint"`
MaximumFee int64 `cbor:"10,keyasint"`
MaximumStake int64 `cbor:"11,keyasint"`
SortitionInterval uint32 `cbor:"8,keyasint"`
FeeFraction float64 `cbor:"9,keyasint"`
MinimumFee int64 `cbor:"10,keyasint"`
MaximumFee int64 `cbor:"11,keyasint"`
MaximumStake int64 `cbor:"12,keyasint"`
}

func DefaultParams() Params {
Expand All @@ -25,6 +26,7 @@ func DefaultParams() Params {
TransactionToLiveInterval: 8640, // one day
BondInterval: 360, // one hour
UnbondInterval: 181440, // 21 days
SortitionInterval: 7,
FeeFraction: 0.0001,
MinimumFee: 1000,
MaximumFee: 100000000,
Expand Down
20 changes: 20 additions & 0 deletions util/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,26 @@ func SafeCmp(s1, s2 []byte) bool {
return subtle.ConstantTimeCompare(s1, s2) == 1
}

// Merge accepts multiple slices and returns a single merged slice.
func Merge[T any](slices ...[]T) []T {
var totalLength int

// Calculate the total length of the merged slice.
for _, slice := range slices {
totalLength += len(slice)
}

// Create a merged slice with the appropriate capacity.
merged := make([]T, 0, totalLength)

// Append each input slice to the merged slice.
for _, slice := range slices {
merged = append(merged, slice...)
}

return merged
}

// Reverse replace the contents of a slice with the same elements but in
// reverse order.
func Reverse[S ~[]E, E any](s S) {
Expand Down
19 changes: 19 additions & 0 deletions util/slice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,25 @@ func TestSafeCmp(t *testing.T) {
assert.False(t, SafeCmp([]byte{1, 2, 3, 3}, []byte{1, 2, 3}))
}

func TestMerge(t *testing.T) {
tests := []struct {
slices [][]byte
merged []byte
}{
{[][]byte{nil}, []byte{}},
{[][]byte{{0, 1, 2}}, []byte{0, 1, 2}},
{[][]byte{{}}, []byte{}},
{[][]byte{{}, {}}, []byte{}},
{[][]byte{{0}, {0}}, []byte{0, 0}},
{[][]byte{{0}, {1}, {2}}, []byte{0, 1, 2}},
}

for _, test := range tests {
merged := Merge(test.slices...)
assert.Equal(t, merged, test.merged)
}
}

func TestReverse(t *testing.T) {
tests := []struct {
slice []byte
Expand Down