Skip to content

Commit

Permalink
Add an account builder [#3587]
Browse files Browse the repository at this point in the history
  • Loading branch information
firelizzard18 committed Apr 3, 2024
1 parent 73886e0 commit c942a19
Show file tree
Hide file tree
Showing 24 changed files with 688 additions and 143 deletions.
6 changes: 3 additions & 3 deletions cmd/accumulated/cmd_init_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,17 +207,17 @@ func initNetworkLocalFS(cmd *cobra.Command, netInit *accumulated.NetworkInit) {

func buildGenesis(network *accumulated.NetworkInit) map[string][]byte {
var factomAddresses func() (io.Reader, error)
var snapshots []func() (ioutil2.SectionReader, error)
var snapshots []func(*core.GlobalValues) (ioutil2.SectionReader, error)
if flagInit.FactomAddresses != "" {
factomAddresses = func() (io.Reader, error) { return os.Open(flagInit.FactomAddresses) }
}
for _, filename := range flagInit.Snapshots {
filename := filename // See docs/developer/rangevarref.md
snapshots = append(snapshots, func() (ioutil2.SectionReader, error) { return os.Open(filename) })
snapshots = append(snapshots, func(*core.GlobalValues) (ioutil2.SectionReader, error) { return os.Open(filename) })
}
if flagInit.FaucetSeed != "" {
b := createFaucet(strings.Split(flagInit.FaucetSeed, " "))
snapshots = append(snapshots, func() (ioutil2.SectionReader, error) {
snapshots = append(snapshots, func(*core.GlobalValues) (ioutil2.SectionReader, error) {
return ioutil2.NewBuffer(b), nil
})
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/accumulated/run/devnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/multiformats/go-multiaddr"
"gitlab.com/accumulatenetwork/accumulate/exp/faucet"
"gitlab.com/accumulatenetwork/accumulate/exp/ioutil"
"gitlab.com/accumulatenetwork/accumulate/internal/core"
"gitlab.com/accumulatenetwork/accumulate/internal/logging"
"gitlab.com/accumulatenetwork/accumulate/internal/node/genesis"
"gitlab.com/accumulatenetwork/accumulate/pkg/errors"
Expand Down Expand Up @@ -262,8 +263,8 @@ func (d *DevnetConfiguration) buildGenesis(inst *Instance, cfg *Config, nodes []
GenesisGlobals: v,
OperatorKeys: [][]byte{mainPubKey},
ConsensusParams: tmtypes.DefaultConsensusParams(),
Snapshots: []func() (ioutil.SectionReader, error){
func() (ioutil.SectionReader, error) { return ioutil.NewBuffer(faucetSnapshot), nil },
Snapshots: []func(*core.GlobalValues) (ioutil.SectionReader, error){
func(*core.GlobalValues) (ioutil.SectionReader, error) { return ioutil.NewBuffer(faucetSnapshot), nil },
},
})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/core/execute/multi/multi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestVersionSwitch(t *testing.T) {
sim := NewSim(t,
simulator.SimpleNetwork(t.Name(), 3, 1), // TODO Change to 3 after fixing anchor healing
simulator.GenesisWith(GenesisTime, g),
simulator.SkipProposalCheck, // FIXME should not be necessary
simulator.SkipProposalCheck(), // FIXME should not be necessary
)

alice := AccountUrl("alice")
Expand Down
3 changes: 1 addition & 2 deletions internal/core/execute/v1/simulator/simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ type SimulatorOptions struct {
LogLevels string
OpenDB func(partition string, nodeIndex int, logger log.Logger) *database.Database
FactomAddresses func() (io.Reader, error)
Snapshots []func() (ioutil2.SectionReader, error)
}

type Simulator struct {
Expand Down Expand Up @@ -316,7 +315,7 @@ func (s *Simulator) InitFromGenesisWith(values *core.GlobalValues) {
// The simulator only runs one DNN so set the threshold low
values.Globals.ValidatorAcceptThreshold.Set(1, 1000)

genDocs, err := accumulated.BuildGenesisDocs(s.netInit, values, GenesisTime, s.Logger, s.opts.FactomAddresses, s.opts.Snapshots)
genDocs, err := accumulated.BuildGenesisDocs(s.netInit, values, GenesisTime, s.Logger, s.opts.FactomAddresses, nil)
require.NoError(s, err)

// Execute bootstrap after the entire network is known
Expand Down
2 changes: 1 addition & 1 deletion internal/node/daemon/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func ConfigureNodePorts(node *NodeInit, cfg *config.Config, part protocol.Partit
cfg.Accumulate.API.ListenAddress = node.Listen().Scheme("http").PartitionType(part).AccumulateAPI().String()
}

func BuildGenesisDocs(network *NetworkInit, globals *core.GlobalValues, time time.Time, logger log.Logger, factomAddresses func() (io.Reader, error), snapshots []func() (ioutil2.SectionReader, error)) (map[string][]byte, error) {
func BuildGenesisDocs(network *NetworkInit, globals *core.GlobalValues, time time.Time, logger log.Logger, factomAddresses func() (io.Reader, error), snapshots []func(*core.GlobalValues) (ioutil2.SectionReader, error)) (map[string][]byte, error) {
docs := map[string][]byte{}
var operators [][]byte
netinfo := new(protocol.NetworkDefinition)
Expand Down
12 changes: 9 additions & 3 deletions internal/node/genesis/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type InitOpts struct {

// Preloaded data
FactomAddresses func() (io.Reader, error)
Snapshots []func() (ioutil2.SectionReader, error)
Snapshots []func(*core.GlobalValues) (ioutil2.SectionReader, error)

// Flags
IncludeHistoryFromSnapshots bool
Expand All @@ -64,6 +64,7 @@ type InitOpts struct {
func Init(snapshotWriter io.WriteSeeker, opts InitOpts) error {
// Initialize globals
gg := core.NewGlobals(opts.GenesisGlobals)
opts.GenesisGlobals = gg

// Build the routing table
var bvns []string
Expand Down Expand Up @@ -460,7 +461,7 @@ func (b *bootstrap) unpackSnapshots() error {
var accounts []*url.URL
seen := map[[32]byte]bool{}
for _, open := range b.Snapshots {
file, err := open()
file, err := open(b.GenesisGlobals)
if err != nil {
return errors.UnknownError.Wrap(err)
}
Expand All @@ -485,6 +486,11 @@ func (b *bootstrap) unpackSnapshots() error {
return false, nil
}

// Skip system accounts
if _, ok := protocol.ParsePartitionUrl(u); ok {
return false, nil
}

// Track ACME issued
if e.Key.Len() == 3 && e.Key.Get(2) == "Main" {
acct, _ := protocol.UnmarshalAccount(e.Value)
Expand Down Expand Up @@ -565,7 +571,7 @@ func (b *bootstrap) unpackSnapshots() error {

// Restore messages
for _, open := range b.Snapshots {
file, err := open()
file, err := open(b.GenesisGlobals)
if err != nil {
return errors.UnknownError.Wrap(err)
}
Expand Down
Loading

0 comments on commit c942a19

Please sign in to comment.