diff --git a/common/random_string.go b/common/random_string.go index d3a9006b802b932589f8e182b671952dd34870b6..159478c3ab653a3c7e9c6daf44c24a8a11d39496 100644 --- a/common/random_string.go +++ b/common/random_string.go @@ -2,7 +2,7 @@ package common import "math/rand" -const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" +const letterBytes = "abcdefABCDEF0123456789" const ( letterIdxBits = 6 // 6 bits to represent a letter index letterIdxMask = 1<<letterIdxBits - 1 // All 1-bits, as many as letterIdxBits diff --git a/common/tx.go b/common/tx.go index 615e83a95ec7d998e4253092b9f5aa77f1546996..5edafc8517edc3f0c3530232c9e31cf7ac9786a5 100644 --- a/common/tx.go +++ b/common/tx.go @@ -2,9 +2,9 @@ package common import ( "crypto/sha256" - "encoding/binary" "errors" "fmt" + "math/big" "strings" "gitlab.com/thorchain/thornode/common/cosmos" @@ -45,11 +45,14 @@ func (tx TxID) Equals(tx2 TxID) bool { return strings.EqualFold(tx.String(), tx2.String()) } -func (tx TxID) HashWithBlockHeight(blockHeight int64) int64 { - toHash := fmt.Sprintf("%s|%v", tx.String(), blockHeight) - checksum := sha256.Sum256([]byte(toHash)) - // using uint32 to avoid overflows - return int64(binary.BigEndian.Uint32(checksum[:4])) +func (tx TxID) Int64() int64 { + last8Chars := tx.String()[len(tx.String())-8:] + // using last8 chars to prevent negative int64 + val, success := new(big.Int).SetString(last8Chars, 16) + if !success { + panic("Failed to convert") + } + return val.Int64() } // IsEmpty return true when the tx represent empty string diff --git a/x/thorchain/manager_slasher_current.go b/x/thorchain/manager_slasher_current.go index 3a4fcaa61eae04098927bb96c6dc65519b7b3c3f..fa90caa2dc588418664e37b80bda3c1918f12539 100644 --- a/x/thorchain/manager_slasher_current.go +++ b/x/thorchain/manager_slasher_current.go @@ -386,7 +386,7 @@ func (s *SlasherVCUR) LackSigning(ctx cosmos.Context, mgr Manager) error { vault = active[0] } } else { - rep := int(tx.InHash.HashWithBlockHeight(ctx.BlockHeight())) + rep := int(tx.InHash.Int64() + ctx.BlockHeight()) if vault.PubKey.Equals(available[rep%len(available)].PubKey) { // looks like the new vault is going to be the same as the // old vault, increment rep to ensure a differ asgard is