Skip to content
This repository has been archived by the owner on May 13, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1153 from silasdavis/cut-through-red-state
Browse files Browse the repository at this point in the history
Cut through red state
  • Loading branch information
Greg Hill authored Jun 20, 2019
2 parents 2a81d33 + 1941c69 commit 0b2f0f5
Show file tree
Hide file tree
Showing 109 changed files with 984 additions and 1,096 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,8 @@ push_ci_image: build_ci_image

.PHONY: ready_for_pull_request
ready_for_pull_request: docs fix

.PHONY: staticcheck
staticcheck:
go get honnef.co/go/tools/cmd/staticcheck
staticcheck ./...
4 changes: 2 additions & 2 deletions acm/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestDecodeConcrete(t *testing.T) {
require.NoError(t, err)

assert.Equal(t, concreteAcc, concreteAccOut)
concreteAccOut, err = Decode([]byte("flungepliffery munknut tolopops"))
_, err = Decode([]byte("flungepliffery munknut tolopops"))
assert.Error(t, err)
}

Expand Down Expand Up @@ -116,7 +116,7 @@ func TestAccountTags(t *testing.T) {
assert.Equal(t, "send | call | createContract | createAccount | bond | name | proposal | input | batch | hasBase | hasRole", str)
str, _ = tagged.Get("Roles")
assert.Equal(t, "frogs;dogs", str)
str, _ = tagged.Get("Code")
tagged.Get("Code")
qry, err := query.New("Code CONTAINS '0116002556001600360006101000A815'")
require.NoError(t, err)
assert.True(t, qry.Matches(tagged))
Expand Down
1 change: 1 addition & 0 deletions acm/acmstate/state_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ func TestStateCache_Sync(t *testing.T) {
newAcc := acm.NewAccountFromSecret("newAcc")
// Create account
err := cache.UpdateAccount(newAcc)
require.NoError(t, err)

// Set balance for account
balance := uint64(24)
Expand Down
4 changes: 3 additions & 1 deletion acm/bytecode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func TestBytecode_MarshalJSON(t *testing.T) {

bytecodeOut := new(Bytecode)
err = json.Unmarshal(bs, bytecodeOut)
require.NoError(t, err)

assert.Equal(t, bytecode, *bytecodeOut)
}
Expand All @@ -41,6 +42,7 @@ func TestBytecode_MarshalText(t *testing.T) {

bytecodeOut := new(Bytecode)
err = bytecodeOut.UnmarshalText(bs)
require.NoError(t, err)

assert.Equal(t, bytecode, *bytecodeOut)
}
Expand Down Expand Up @@ -80,6 +82,6 @@ func TestBytecode_Tokens(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, []string{}, tokens)

tokens, err = Bytecode(bc.MustSplice(asm.PUSH3, 1, 2)).Tokens()
_, err = Bytecode(bc.MustSplice(asm.PUSH3, 1, 2)).Tokens()
assert.Error(t, err, "not enough bytes to push")
}
4 changes: 2 additions & 2 deletions acm/validator/bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ func TestBucket_AlterPower(t *testing.T) {
require.NoError(t, err)
require.Equal(t, big3.Int64(), flow.Int64())

flow, err = bucket.AlterPower(pubA, new(big.Int).Add(maxTotalVotingPower, big1))
_, err = bucket.AlterPower(pubA, new(big.Int).Add(maxTotalVotingPower, big1))
require.Error(t, err, "should fail as we would breach total power")

flow, err = bucket.AlterPower(pubB, big1)
_, err = bucket.AlterPower(pubB, big1)
require.Error(t, err, "should fail as we would breach total power")

// Drop A and raise B - should now succeed
Expand Down
2 changes: 1 addition & 1 deletion acm/validator/ring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestValidatorsRing_AlterPower(t *testing.T) {
vs = Copy(vsBase)
vw = NewRing(vs, 5)
powA, powB, powC = 7000, 23, 310
powerChange, totalFlow, err = alterPowers(t, vw, powA, powB, powC)
_, _, err = alterPowers(t, vw, powA, powB, powC)
require.Error(t, err)

powA, powB, powC = 7000, 23, 309
Expand Down
1 change: 1 addition & 0 deletions binary/bytes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ func TestHexBytes_MarshalText(t *testing.T) {
assert.Equal(t, "\"0102030405\"", string(out))
bs2 := new(HexBytes)
err = json.Unmarshal(out, bs2)
require.NoError(t, err)
assert.Equal(t, bs, *bs2)
}
31 changes: 0 additions & 31 deletions binary/integer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package binary

import (
"encoding/binary"
"math"
"math/big"
)
Expand All @@ -26,36 +25,6 @@ var tt256 = new(big.Int).Lsh(big1, 256)
var tt256m1 = new(big.Int).Sub(new(big.Int).Lsh(big1, 256), big1)
var tt255 = new(big.Int).Lsh(big1, 255)

//--------------------------------------------------------------------------------

func PutUint64(dest []byte, i uint64) {
binary.BigEndian.PutUint64(dest, i)
}

func GetUint64(src []byte) uint64 {
return binary.BigEndian.Uint64(src)
}

func Uint64Bytes(v uint64) []byte {
bs := make([]byte, 8)
binary.BigEndian.PutUint64(bs, v)
return bs
}

func PutInt64(dest []byte, i int64) {
binary.BigEndian.PutUint64(dest, uint64(i))
}

func GetInt64(src []byte) int64 {
return int64(binary.BigEndian.Uint64(src))
}

func Int64Bytes(v int64) []byte {
bs := make([]byte, 8)
binary.BigEndian.PutUint64(bs, uint64(v))
return bs
}

// Returns whether a + b would be a uint64 overflow
func IsUint64SumOverflow(a, b uint64) bool {
return math.MaxUint64-a < b
Expand Down
6 changes: 0 additions & 6 deletions binary/integer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,6 @@ func TestS256(t *testing.T) {
assertBigIntEqual(t, expected, signed, "Out of twos complement bounds")
}

func TestPutUint64BE(t *testing.T) {
bs := make([]byte, 8)
PutUint64(bs, 245343)
assert.Equal(t, "000000000003BE5F", fmt.Sprintf("%X", bs))
}

func TestSignExtend(t *testing.T) {
assertSignExtend(t, 16, 0,
"0000 0000 1001 0000",
Expand Down
9 changes: 5 additions & 4 deletions binary/word256.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package binary

import (
"bytes"
"encoding/binary"
"fmt"
"math/big"
"sort"
Expand Down Expand Up @@ -128,12 +129,12 @@ func (w Word256) Size() int {
}

func Uint64ToWord256(i uint64) (word Word256) {
PutUint64(word[24:], i)
binary.BigEndian.PutUint64(word[24:], i)
return
}

func Int64ToWord256(i int64) (word Word256) {
PutInt64(word[24:], i)
binary.BigEndian.PutUint64(word[24:], uint64(i))
return
}

Expand All @@ -148,11 +149,11 @@ func LeftPadWord256(bz []byte) (word Word256) {
}

func Uint64FromWord256(word Word256) uint64 {
return GetUint64(word.Postfix(8))
return binary.BigEndian.Uint64(word.Postfix(8))
}

func Int64FromWord256(word Word256) int64 {
return GetInt64(word.Postfix(8))
return int64(Uint64FromWord256(word))
}

//-------------------------------------
Expand Down
1 change: 1 addition & 0 deletions binary/word256_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func TestWord256_MarshalText(t *testing.T) {
assert.Equal(t, "\"0102030405000000000000000000000000000000000000000000000000000000\"", string(out))
bs2 := new(Word256)
err = json.Unmarshal(out, bs2)
require.NoError(t, err)
assert.Equal(t, w, *bs2)
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/burrow/commands/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ func Configure(output Output) func(cmd *cli.Cmd) {
output.Fatalf("Could not create remote key client: %v", err)
}
conf.GenesisDoc, err = genesisSpec.GenesisDoc(keyClient, *generateNodeKeys || *pool)
if err != nil {
output.Fatalf("could not realise GenesisSpec: %v", err)
}
}

if err != nil {
output.Fatalf("could not realise GenesisSpec: %v", err)
}
}

if *chainNameOpt != "" {
Expand Down
6 changes: 6 additions & 0 deletions cmd/burrow/commands/examine.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ func Examine(output Output) func(cmd *cli.Cmd) {

cmd.Action = func() {
start, end, err := parseRange(*rangeArg)
if err != nil {
output.Fatalf("could not parse range '%s': %v", *rangeArg, err)
}

err = explorer.Blocks(start, end,
func(block *bcm.Block) error {
Expand All @@ -61,6 +64,9 @@ func Examine(output Output) func(cmd *cli.Cmd) {

cmd.Action = func() {
start, end, err := parseRange(*rangeArg)
if err != nil {
output.Fatalf("could not parse range '%s': %v", *rangeArg, err)
}

err = explorer.Blocks(start, end,
func(block *bcm.Block) error {
Expand Down
5 changes: 3 additions & 2 deletions consensus/abci/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ type App struct {
// State
blockchain *bcm.Blockchain
validators Validators
checkTx func(txBytes []byte) types.ResponseCheckTx
deliverTx func(txBytes []byte) types.ResponseCheckTx
mempoolLocker sync.Locker
authorizedPeersProvider PeersFilterProvider
// We need to cache these from BeginBlock for when we need actually need it in Commit
Expand Down Expand Up @@ -125,6 +123,9 @@ func (app *App) InitChain(chain types.RequestInitChain) (respInitChain types.Res
}
for _, v := range chain.Validators {
pk, err := crypto.PublicKeyFromABCIPubKey(v.GetPubKey())
if err != nil {
panic(err)
}
err = app.checkValidatorMatches(currentSet, types.Validator{Address: pk.GetAddress().Bytes(), Power: v.Power})
if err != nil {
panic(err)
Expand Down
12 changes: 6 additions & 6 deletions consensus/tendermint/sign_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,25 @@ func (lsi *LastSignedInfo) SignProposal(sign tmCryptoSigner, chainID string, pro
// returns error if HRS regression or no SignBytes. returns true if HRS is unchanged
func (lsi *LastSignedInfo) checkHRS(height int64, round int, step int8) (bool, error) {
if lsi.Height > height {
return false, errors.New("Height regression")
return false, errors.New("height regression")
}

if lsi.Height == height {
if lsi.Round > round {
return false, errors.New("Round regression")
return false, errors.New("round regression")
}

if lsi.Round == round {
if lsi.Step > step {
return false, errors.New("Step regression")
return false, errors.New("step regression")
} else if lsi.Step == step {
if lsi.SignBytes != nil {
if lsi.Signature == nil {
panic("pv: Signature is nil but SignBytes is not!")
}
return true, nil
}
return false, errors.New("No Signature found")
return false, errors.New("no Signature found")
}
}
}
Expand Down Expand Up @@ -125,7 +125,7 @@ func (lsi *LastSignedInfo) signVote(sign tmCryptoSigner, chainID string, vote *t
vote.Timestamp = timestamp
vote.Signature = lsi.Signature
} else {
err = fmt.Errorf("Conflicting data")
err = fmt.Errorf("conflicting data")
}
return err
}
Expand Down Expand Up @@ -161,7 +161,7 @@ func (lsi *LastSignedInfo) signProposal(sign tmCryptoSigner, chainID string, pro
proposal.Timestamp = timestamp
proposal.Signature = lsi.Signature
} else {
err = fmt.Errorf("Conflicting data")
err = fmt.Errorf("conflicting data")
}
return err
}
Expand Down
2 changes: 1 addition & 1 deletion core/kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func (kern *Kernel) supervise() {
shutdownCh := make(chan os.Signal, 1)
reloadCh := make(chan os.Signal, 1)
syncCh := make(chan os.Signal, 1)
signal.Notify(shutdownCh, syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL)
signal.Notify(shutdownCh, syscall.SIGINT, syscall.SIGTERM)
signal.Notify(reloadCh, syscall.SIGHUP)
signal.Notify(syncCh, syscall.SIGUSR1)
for {
Expand Down
3 changes: 2 additions & 1 deletion crypto/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package crypto
import (
"bytes"
"crypto/sha256"
bin "encoding/binary"
"encoding/json"
"fmt"

Expand Down Expand Up @@ -190,7 +191,7 @@ func Nonce(caller Address, nonce []byte) []byte {
// Obtain a nearly unique nonce based on a montonic account sequence number
func SequenceNonce(address Address, sequence uint64) []byte {
bs := make([]byte, 8)
binary.PutUint64(bs, sequence)
bin.BigEndian.PutUint64(bs, sequence)
return Nonce(address, bs)
}

Expand Down
2 changes: 2 additions & 0 deletions crypto/address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func TestAddress_MarshalJSON(t *testing.T) {

addrOut := new(Address)
err = json.Unmarshal(bs, addrOut)
require.NoError(t, err)

assert.Equal(t, addr, *addrOut)
}
Expand All @@ -74,6 +75,7 @@ func TestAddress_MarshalText(t *testing.T) {

addrOut := new(Address)
err = addrOut.UnmarshalText(bs)
require.NoError(t, err)

assert.Equal(t, addr, *addrOut)
}
Expand Down
1 change: 1 addition & 0 deletions crypto/public_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func TestPublicKeySerialisation(t *testing.T) {
require.NoError(t, err)
var pubOut PublicKey
err = proto.Unmarshal(bs, &pubOut)
require.NoError(t, err)
assert.Equal(t, pub, pubOut)

bs, err = json.Marshal(pub)
Expand Down
20 changes: 2 additions & 18 deletions deploy/compile/compilers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"

"github.com/hyperledger/burrow/crypto"
Expand Down Expand Up @@ -156,10 +155,8 @@ func Compile(file string, optimize bool, workDir string, libraries map[string]st
input.Settings.Libraries = make(map[string]map[string]string)
input.Settings.Libraries[""] = make(map[string]string)

if libraries != nil {
for l, a := range libraries {
input.Settings.Libraries[""][l] = "0x" + a
}
for l, a := range libraries {
input.Settings.Libraries[""][l] = "0x" + a
}

command, err := json.Marshal(input)
Expand Down Expand Up @@ -253,16 +250,3 @@ func PrintResponse(resp Response, cli bool, logger *logging.Logger) {
}
}
}

func extractObjectNames(script []byte) ([]string, error) {
regExpression, err := regexp.Compile("(contract|library) (.+?) (is)?(.+?)?({)")
if err != nil {
return nil, err
}
objectNamesList := regExpression.FindAllSubmatch(script, -1)
var objects []string
for _, objectNames := range objectNamesList {
objects = append(objects, string(objectNames[2]))
}
return objects, nil
}
Loading

0 comments on commit 0b2f0f5

Please sign in to comment.