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

feat: add genesis packages with transaction signing #3280

Merged
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
aa15626
feat: add genesis packages with transaction signing
Villaquiranm Dec 5, 2024
169e2a3
fix linter
Villaquiranm Dec 5, 2024
069c01b
Merge branch 'master' into feat/sign-transactions-genesis
Villaquiranm Dec 6, 2024
b46af72
Merge branch 'master' of github.com:gnolang/gno into feat/sign-transa…
Villaquiranm Dec 9, 2024
4eb4f8a
fix tests
Villaquiranm Dec 9, 2024
8a72345
Merge branch 'master' of github.com:gnolang/gno into feat/sign-transa…
Villaquiranm Dec 12, 2024
90e0c0c
testing fix
Villaquiranm Dec 12, 2024
af86152
sign packages by default with test1 account
Villaquiranm Dec 12, 2024
46d6129
Merge branch 'master' of github.com:gnolang/gno into feat/sign-transa…
Villaquiranm Dec 12, 2024
bf39fe7
Add test
Villaquiranm Dec 12, 2024
66b1725
remove temporary fix on gnostart
Villaquiranm Dec 12, 2024
5b4aadf
change default name to dev
Villaquiranm Dec 12, 2024
98f9ae0
change back to tendermit_test
Villaquiranm Dec 12, 2024
d70fa9b
do not check verification on gnodev tests
Villaquiranm Dec 12, 2024
ed0784f
Merge branch 'master' of github.com:gnolang/gno into feat/sign-transa…
Villaquiranm Dec 17, 2024
ed1c3c6
configure genesis transaction verification depending on service
Villaquiranm Dec 17, 2024
1ea0bca
Merge branch 'master' of github.com:gnolang/gno into feat/sign-transa…
Villaquiranm Dec 17, 2024
8dfb9bf
Fix tests
Villaquiranm Dec 17, 2024
6c8775f
Merge branch 'master' of github.com:gnolang/gno into feat/sign-transa…
Villaquiranm Dec 17, 2024
037f832
Merge branch 'master' into feat/sign-transactions-genesis
Villaquiranm Dec 18, 2024
76f3fdd
Merge branch 'master' into feat/sign-transactions-genesis
Villaquiranm Dec 18, 2024
c72fe3c
fix txtar tests
Villaquiranm Dec 18, 2024
d0715e9
fix TestCallSingle_Integration test
Villaquiranm Dec 18, 2024
6bc9df9
Merge branch 'master' into feat/sign-transactions-genesis
Villaquiranm Dec 19, 2024
94ad25b
Merge branch 'master' into feat/sign-transactions-genesis
Villaquiranm Dec 19, 2024
2bddc48
Fix tests
Villaquiranm Dec 19, 2024
8b27abe
add comment on gnoHome config
Villaquiranm Dec 19, 2024
a0d0b9c
Merge branch 'master' of github.com:gnolang/gno into feat/sign-transa…
Villaquiranm Dec 20, 2024
5aec227
Merge branch 'master' into feat/sign-transactions-genesis
Villaquiranm Dec 20, 2024
bb2f53f
Merge branch 'master' into feat/sign-transactions-genesis
Villaquiranm Dec 20, 2024
3c887a9
make tidy
Villaquiranm Dec 20, 2024
6e8c63f
Merge branch 'master' into feat/sign-transactions-genesis
Villaquiranm Dec 23, 2024
9430d13
Merge branch 'master' into feat/sign-transactions-genesis
Villaquiranm Dec 23, 2024
64cf627
Merge branch 'master' into feat/sign-transactions-genesis
Villaquiranm Dec 25, 2024
bbc1055
Merge branch 'master' into feat/sign-transactions-genesis
Villaquiranm Dec 30, 2024
0394a1b
Merge branch 'master' into feat/sign-transactions-genesis
Villaquiranm Jan 2, 2025
7f1fbc9
Merge branch 'master' into feat/sign-transactions-genesis
Villaquiranm Jan 6, 2025
c967c2f
Solve comments
Villaquiranm Jan 6, 2025
14c6906
Merge branch 'master' into feat/sign-transactions-genesis
Villaquiranm Jan 7, 2025
09dce43
fix more comments :)
Villaquiranm Jan 7, 2025
9f59ccb
make tidy
Villaquiranm Jan 7, 2025
e33600f
sign load packages on integration tests
Villaquiranm Jan 7, 2025
2a67769
improve SignTx function
Villaquiranm Jan 8, 2025
30c5a42
Merge branch 'master' of github.com:gnolang/gno into feat/sign-transa…
Villaquiranm Jan 8, 2025
7a134ab
fix build
Villaquiranm Jan 8, 2025
cfcc35d
improve check
Villaquiranm Jan 8, 2025
6df2bc9
Merge branch 'master' into feat/sign-transactions-genesis
Villaquiranm Jan 9, 2025
e0bb164
remove creator from LoadPackages func
Villaquiranm Jan 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions contribs/gnodev/pkg/dev/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,8 @@ func (n *Node) rebuildNode(ctx context.Context, genesis gnoland.GnoGenesisState)
// Speed up stdlib loading after first start (saves about 2-3 seconds on each reload).
nodeConfig.CacheStdlibLoad = true
nodeConfig.Genesis.ConsensusParams.Block.MaxGas = n.config.MaxGasPerBlock
// Genesis verification is always false with Gnodev
nodeConfig.SkipGenesisVerification = true

// recoverFromError handles panics and converts them to errors.
recoverFromError := func() {
Expand Down
4 changes: 4 additions & 0 deletions contribs/gnogenesis/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ require (
github.com/peterbourgon/ff/v3 v3.4.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/rs/cors v1.11.1 // indirect
github.com/rs/xid v1.6.0 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
Expand All @@ -45,13 +46,16 @@ require (
go.opentelemetry.io/otel/trace v1.29.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
go.uber.org/zap/exp v0.3.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 // indirect
golang.org/x/mod v0.20.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/term v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/tools v0.24.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240822170219-fc7c04adadcd // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240822170219-fc7c04adadcd // indirect
google.golang.org/grpc v1.65.0 // indirect
Expand Down
8 changes: 8 additions & 0 deletions contribs/gnogenesis/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

118 changes: 92 additions & 26 deletions contribs/gnogenesis/internal/txs/txs_add_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,51 @@ import (
"errors"
"flag"
"fmt"
"os"

"github.com/gnolang/gno/tm2/pkg/crypto"
"github.com/gnolang/gno/tm2/pkg/crypto/keys"

"github.com/gnolang/gno/gno.land/pkg/gnoclient"
"github.com/gnolang/gno/gno.land/pkg/gnoland"
"github.com/gnolang/gno/gno.land/pkg/gnoland/ugnot"
"github.com/gnolang/gno/gno.land/pkg/integration"
"github.com/gnolang/gno/tm2/pkg/bft/types"
"github.com/gnolang/gno/tm2/pkg/commands"
"github.com/gnolang/gno/tm2/pkg/std"
)

var (
errInvalidPackageDir = errors.New("invalid package directory")
errInvalidDeployerAddr = errors.New("invalid deployer address")
)
var errInvalidPackageDir = errors.New("invalid package directory")

// Keep in sync with gno.land/cmd/start.go
var (
defaultCreator = crypto.MustAddressFromString("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // test1
genesisDeployFee = std.NewFee(50000, std.MustParseCoin(ugnot.ValueString(1000000)))
)
var genesisDeployFee = std.NewFee(50000, std.MustParseCoin(ugnot.ValueString(1000000)))

type addPkgCfg struct {
txsCfg *txsCfg
deployerAddress string
txsCfg *txsCfg
keyName string
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved
gnoHome string // default GNOHOME env var, just here to ease testing with parallel tests
insecurePasswordStdin bool
}

func (c *addPkgCfg) RegisterFlags(fs *flag.FlagSet) {
fs.StringVar(
&c.deployerAddress,
"deployer-address",
defaultCreator.String(),
"the address that will be used to deploy the package",
&c.keyName,
"key-name",
"",
"The package deployer key name or address",
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved
)

fs.StringVar(
&c.gnoHome,
"gno-home",
os.Getenv("GNOHOME"),
"the gno home directory",
)

fs.BoolVar(
&c.insecurePasswordStdin,
"insecure-password-stdin",
false,
"the gno home directory",
)
}

Expand Down Expand Up @@ -76,27 +89,28 @@ func execTxsAddPackages(
return errInvalidPackageDir
}

var (
creator = defaultCreator
err error
)
signer, err := signerWithConfig(cfg, io, genesis.ChainID)
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return fmt.Errorf("unable to load signer, %w", err)
}

// Check if the deployer address is set
if cfg.deployerAddress != defaultCreator.String() {
creator, err = crypto.AddressFromString(cfg.deployerAddress)
if err != nil {
return fmt.Errorf("%w, %w", errInvalidDeployerAddr, err)
}
info, err := signer.Info()
if err != nil {
return fmt.Errorf("unable to get signer info, %w", err)
}

parsedTxs := make([]gnoland.TxWithMetadata, 0)
for _, path := range args {
// Generate transactions from the packages (recursively)
txs, err := gnoland.LoadPackagesFromDir(path, creator, genesisDeployFee)
txs, err := gnoland.LoadPackagesFromDir(path, info.GetAddress(), genesisDeployFee)
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return fmt.Errorf("unable to load txs from directory, %w", err)
}

if err := signTxs(txs, signer); err != nil {
return fmt.Errorf("unable to sign txs, %w", err)
}

parsedTxs = append(parsedTxs, txs...)
}

Expand All @@ -117,3 +131,55 @@ func execTxsAddPackages(

return nil
}

func signTxs(txs []gnoland.TxWithMetadata, signer *gnoclient.SignerFromKeybase) error {
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved
for index, tx := range txs {
signBytes, err := tx.Tx.GetSignBytes(signer.ChainID, 0, 0)
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return fmt.Errorf("unable to load txs from directory, %w", err)
}
signature, publicKey, err := signer.Keybase.Sign(signer.Account, signer.Password, signBytes)
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved
txs[index].Tx.Signatures = []std.Signature{
{
PubKey: publicKey,
Signature: signature,
},
}
if err != nil {
return fmt.Errorf("unable sign tx %w", err)
}
}

return nil
}

func signerWithConfig(cfg *addPkgCfg, io commands.IO, chainID string) (*gnoclient.SignerFromKeybase, error) {
var (
keyname = integration.DefaultAccount_Name
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved
pass string
kb keys.Keybase
err error
)

if cfg.keyName != "" {
keyname = cfg.keyName
kb, err = keys.NewKeyBaseFromDir(cfg.gnoHome)
if err != nil {
return nil, fmt.Errorf("unable to load keybase: %w", err)
}
pass, err = io.GetPassword("Enter password.", cfg.insecurePasswordStdin)
if err != nil {
return nil, fmt.Errorf("cannot read password: %w", err)
}
} else {
kb = keys.NewInMemory()
kb.CreateAccount(integration.DefaultAccount_Name, integration.DefaultAccount_Seed, "", "", 0, 0)
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved
}

return &gnoclient.SignerFromKeybase{
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved
Account: keyname,
ChainID: chainID,
Keybase: kb,
Password: pass,
}, nil
}
Loading
Loading