Skip to content

Commit

Permalink
Merge branch 'new-network-connection' into itest-light-node-state-hash
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeykiselev committed Dec 26, 2024
2 parents 0f4b79b + 16a32cb commit 227698f
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 1 deletion.
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ vetcheck:
strict-vet-check:
golangci-lint run -c .golangci-strict.yml

build-chaincmp-native:
@go build -o build/bin/native/chaincmp -ldflags="-X main.version=$(VERSION)" ./cmd/chaincmp
build-chaincmp-linux:
@CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o build/bin/linux-amd64/chaincmp -ldflags="-X main.version=$(VERSION)" ./cmd/chaincmp
build-chaincmp-darwin:
Expand All @@ -89,6 +91,8 @@ dist-chaincmp: release-chaincmp
@cd ./build/bin/linux-amd64/; tar pzcvf ../../dist/chaincmp_$(VERSION)_Linux-amd64.tar.gz ./chaincmp*
@cd ./build/bin/darwin-amd64/; tar pzcvf ../../dist/chaincmp_$(VERSION)_macOS-amd64.tar.gz ./chaincmp*

build-blockcmp-native:
@go build -o build/bin/native/blockcmp -ldflags="-X main.version=$(VERSION)" ./cmd/blockcmp
build-blockcmp-linux:
@CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o build/bin/linux-amd64/blockcmp -ldflags="-X main.version=$(VERSION)" ./cmd/blockcmp
build-blockcmp-darwin:
Expand Down Expand Up @@ -149,6 +153,8 @@ dist-importer: release-importer
@cd ./build/bin/linux-amd64/; tar pzcvf ../../dist/importer_$(VERSION)_Linux-amd64.tar.gz ./importer*
@cd ./build/bin/darwin-amd64/; tar pzcvf ../../dist/importer_$(VERSION)_macOS-amd64.tar.gz ./importer*

build-wallet-native:
@go build -o build/bin/native/wallet ./cmd/wallet
build-wallet-linux:
@CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o build/bin/linux-amd64/wallet ./cmd/wallet
build-wallet-darwin:
Expand All @@ -164,6 +170,8 @@ dist-wallet: release-wallet
@cd ./build/bin/linux-amd64/; tar pzcvf ../../dist/wallet_$(VERSION)_Linux-amd64.tar.gz ./wallet*
@cd ./build/bin/darwin-amd64/; tar pzcvf ../../dist/wallet_$(VERSION)_macOS-amd64.tar.gz ./wallet*

build-rollback-native:
@go build -o build/bin/native/rollback -ldflags="-X 'github.com/wavesplatform/gowaves/pkg/versioning.Version=$(VERSION)'" ./cmd/rollback
build-rollback-linux:
@CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o build/bin/linux-amd64/rollback -ldflags="-X 'github.com/wavesplatform/gowaves/pkg/versioning.Version=$(VERSION)'" ./cmd/rollback
build-rollback-darwin:
Expand All @@ -173,6 +181,8 @@ build-rollback-windows:

release-rollback: ver build-rollback-linux build-rollback-darwin build-rollback-windows

build-compiler-native:
@go build -o build/bin/native/compiler ./cmd/compiler
build-compiler-linux:
@CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o build/bin/linux-amd64/compiler ./cmd/compiler
build-compiler-darwin:
Expand All @@ -188,6 +198,8 @@ dist-compiler: release-compiler
@cd ./build/bin/linux-amd64/; tar pzcvf ../../dist/compiler_$(VERSION)_Linux-amd64.tar.gz ./compiler*
@cd ./build/bin/darwin-amd64/; tar pzcvf ../../dist/compiler_$(VERSION)_macOS-amd64.tar.gz ./compiler*

build-statehash-native:
@go build -o build/bin/native/statehash ./cmd/statehash
build-statehash-linux:
@CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o build/bin/linux-amd64/statehash ./cmd/statehash
build-statehash-darwin:
Expand All @@ -197,6 +209,8 @@ build-statehash-windows:

release-statehash: ver build-statehash-linux build-statehash-darwin build-statehash-windows

build-convert-native:
@go build -o build/bin/native/convert ./cmd/convert
build-convert-linux:
@CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o build/bin/linux-amd64/convert ./cmd/convert
build-convert-darwin:
Expand All @@ -214,6 +228,8 @@ dist-convert: release-convert

dist: clean dist-chaincmp dist-importer dist-node dist-wallet dist-compiler

build: vendor ver build-chaincmp-native build-blockcmp-native build-node-native build-importer-native build-wallet-native build-rollback-native build-compiler-native build-statehash-native build-convert-native

mock:
mockgen -source pkg/miner/utxpool/cleaner.go -destination pkg/miner/utxpool/mock.go -package utxpool stateWrapper
mockgen -source pkg/node/peers/peer_manager.go -destination pkg/mock/peer_manager.go -package mock PeerManager
Expand Down
5 changes: 5 additions & 0 deletions pkg/state/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,11 @@ func (s *testStorageObjects) transferWaves(
s.setWavesBalance(t, to, toBalance, blockID)
}

func (s *testStorageObjects) createAlias(t testing.TB, addr proto.WavesAddress, alias string, blockID proto.BlockID) {
err := s.entities.aliases.createAlias(alias, addr, blockID)
assert.NoError(t, err, "createAlias() failed")
}

func storeScriptByAddress(
stor *blockchainEntitiesStorage,
scheme proto.Scheme,
Expand Down
4 changes: 3 additions & 1 deletion pkg/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -2367,8 +2367,10 @@ func (s *stateManager) RetrieveEntries(account proto.Recipient) ([]proto.DataEnt
return entries, nil
}

// IsStateUntouched returns true if the account has no data entries.
// ATTENTION: Despite the name, this function operates on the newest state. The name is kept for compatibility.
func (s *stateManager) IsStateUntouched(account proto.Recipient) (bool, error) {
addr, err := s.recipientToAddress(account)
addr, err := s.NewestRecipientToAddress(account)
if err != nil {
return false, wrapErr(RetrievalError, err)
}
Expand Down
119 changes: 119 additions & 0 deletions pkg/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -900,3 +900,122 @@ func TestGeneratingBalanceValuesInRide(t *testing.T) {
})
})
}

func TestIsStateUntouched(t *testing.T) {
createTestScript := func(t *testing.T, libV ast.LibraryVersion) *ast.Tree {
const scriptTemplate = `
{-# STDLIB_VERSION %d #-}
{-# CONTENT_TYPE DAPP #-}
{-# SCRIPT_TYPE ACCOUNT #-}
@Callable(i)
func checkStorageUntouchedByAlias(accountAlias: String) = {
let alias = Alias(accountAlias)
let res = if isDataStorageUntouched(alias) then {
unit
} else {
throw("Data storage is not untouched by alias")
}
([], res)
}
`
scriptSrc := fmt.Sprintf(scriptTemplate, libV)
tree, errs := ridec.CompileToTree(scriptSrc)
require.NoError(t, stderrs.Join(errs...), "ride.CompileToTree() failed")
return tree
}
doTest := func(t *testing.T, state *stateManager, testObj *testStorageObjects, libV ast.LibraryVersion) {
// create test accounts
dApp, err := proto.NewKeyPair(binary.BigEndian.AppendUint32(nil, 999))
require.NoError(t, err, "NewKeyPair() failed")
anotherAccount, err := proto.NewKeyPair(binary.BigEndian.AppendUint32(nil, 1))
require.NoError(t, err, "NewKeyPair() failed")
// create test addresses
bs, bsErr := state.BlockchainSettings()
require.NoError(t, bsErr, "BlockchainSettings() failed")
caller, aErr := anotherAccount.Addr(bs.AddressSchemeCharacter)
require.NoError(t, aErr, "Addr() failed")
dAppAddr, aErr := dApp.Addr(bs.AddressSchemeCharacter)
require.NoError(t, aErr, "Addr() failed")
// create test script
tree := createTestScript(t, libV)
// create assertion function for the current state
assertDataStorageByAlias := func(t *testing.T, alias string) {
fc := proto.NewFunctionCall("checkStorageUntouchedByAlias",
proto.Arguments{proto.NewStringArgument(alias)})
env := createNewRideEnv(t, state, dAppAddr, caller, libV)
_, err = ride.CallFunction(env, tree, fc)
require.NoError(t, err, "ride.CallFunction() failed")
}
assertHeight := func(t *testing.T, expectedHeight int) {
nh, hErr := state.NewestHeight()
require.NoError(t, hErr, "NewestHeight() failed")
require.Equal(t, proto.Height(expectedHeight), nh)
}
assertHeight(t, 1) // check that height is 1
// set initial balance for dApp and another account
const (
initialDAppBalance = 100 * proto.PriceConstant
initialAnotherAccountBalance = 500 * proto.PriceConstant
)
testObj.setWavesBalance(t, dAppAddr, balanceProfile{initialDAppBalance, 0, 0}, blockID0) // height 1
testObj.setWavesBalance(t, caller, balanceProfile{initialAnotherAccountBalance, 0, 0}, blockID0) // height 1

// Alias "alice" created and checked in different blocks, should always pass.
testObj.addBlockAndDo(t, blockID1, func(_ proto.BlockID) { // height 2 - create alias "alice".
testObj.createAlias(t, dAppAddr, "alice", blockID1)
})
assertHeight(t, 2)

testObj.addBlockAndDo(t, blockID2, func(_ proto.BlockID) { // height 3 - check data storage by alias "alice".
assertDataStorageByAlias(t, "alice")
})
assertHeight(t, 3)
// Bob alias is created and checked in the same block.
testObj.addBlockAndDo(t, blockID3, func(_ proto.BlockID) { // height 4 - create alias "bob" and check the storage.
testObj.createAlias(t, dAppAddr, "bob", blockID3)
assertDataStorageByAlias(t, "bob")
})
assertHeight(t, 4)
}
t.Run("The data storage can be checked by alias created in the same block", func(t *testing.T) {
generateFeaturesList := func(targetFeature settings.Feature) []settings.Feature {
var feats []settings.Feature
for f := settings.SmallerMinimalGeneratingBalance; f <= targetFeature; f++ {
feats = append(feats, f)
}
return feats
}
activateFeatures := func(t *testing.T, testObj *testStorageObjects, feats []settings.Feature, id proto.BlockID) {
for _, f := range feats {
testObj.activateFeatureWithBlock(t, int16(f), id)
}
}
createMockState := func(t *testing.T, targetFeature settings.Feature) (*stateManager, *testStorageObjects) {
sets := settings.MustDefaultCustomSettings()
sets.LightNodeBlockFieldsAbsenceInterval = 0 // disable absence interval for Light Node
sets.GenerationBalanceDepthFrom50To1000AfterHeight = 1 // set from the first height
state, testObj := createMockStateManager(t, sets)
featuresList := generateFeaturesList(targetFeature)
testObj.addBlock(t, blockID0) // add "genesis" block, height 1
activateFeatures(t, testObj, featuresList, blockID0) // activate features at height 1
testObj.flush(t) // write changes to the storage
return state, testObj
}
t.Run("RideV5, STDLIB_VERSION 5", func(t *testing.T) {
state, testObj := createMockState(t, settings.RideV5)
doTest(t, state, testObj, ast.LibV5)
})
t.Run("RideV6, STDLIB_VERSION 6", func(t *testing.T) {
state, testObj := createMockState(t, settings.RideV6)
doTest(t, state, testObj, ast.LibV6)
})
t.Run("BlockRewardDistribution, STDLIB_VERSION 7", func(t *testing.T) {
state, testObj := createMockState(t, settings.BlockRewardDistribution)
doTest(t, state, testObj, ast.LibV7)
})
t.Run("LightNode, STDLIB_VERSION 8", func(t *testing.T) {
state, testObj := createMockState(t, settings.LightNode)
doTest(t, state, testObj, ast.LibV8)
})
})
}

0 comments on commit 227698f

Please sign in to comment.