burrow, dump & restore

Burrow, Dump & Restore

Dump

Dump will create a dump file of burrow state.

Dump local

create a dump from local Burrow directory

burrow dump --verbose local

It will create a burrow kernel locally from the burrow state DB, then make a dumper which start a goroutine for feeding state data.

// Return a Source that is a Pipe fed from this Dumper's Transmit function
func (ds *Dumper) Source(startHeight, endHeight uint64, options Option) Source {
	p := make(Pipe)
	go func() {
		err := ds.Transmit(p, startHeight, endHeight, options)
		if err != nil {
			p <- msg{err: err}
		}
		close(p)
	}()
	return p
}

Accounts | Names | Events can be dumpped.

Dump remote

pull a dump from a remote Burrow node

burrow dump --verbose remote -c 127.0.0.1:10997

Similarly it will dial to a gRPC dump server, and start streaming the state data.

func (c *dumpClient) GetDump(ctx context.Context, in *GetDumpParam, opts ...grpc.CallOption) (Dump_GetDumpClient, error) {
	stream, err := c.cc.NewStream(ctx, &_Dump_serviceDesc.Streams[0], "/rpcdump.Dump/GetDump", opts...)
	if err != nil {
		return nil, err
	}
	x := &dumpGetDumpClient{stream}
	if err := x.ClientStream.SendMsg(in); err != nil {
		return nil, err
	}
	if err := x.ClientStream.CloseSend(); err != nil {
		return nil, err
	}
	return x, nil
}

func (x *dumpGetDumpClient) Recv() (*dump.Dump, error) {
	m := new(dump.Dump)
	if err := x.ClientStream.RecvMsg(m); err != nil {
		return nil, err
	}
	return m, nil
}

Restore

Restore from a dump file.

burrow restore

// LoadDump restores chain state from the given dump file
func (kern *Kernel) LoadDump(genesisDoc *genesis.GenesisDoc, restoreFile string, silent bool) (err error) {
	var exists bool
	if kern.Blockchain, exists, err = bcm.LoadOrNewBlockchain(kern.database, genesisDoc, kern.Logger); err != nil {
		return fmt.Errorf("error creating or loading blockchain state: %v", err)
	}

	if exists {
		if silent {
			kern.Logger.InfoMsg("State already exists, skipping...")
			return nil
		}
		return fmt.Errorf("existing state found, please remove before restoring")
	}

	kern.Blockchain.SetBlockStore(bcm.NewBlockStore(store.NewBlockStore(kern.database)))

	if kern.State, err = state.MakeGenesisState(kern.database, genesisDoc); err != nil {
		return fmt.Errorf("could not build genesis state: %v", err)
	}

	if len(genesisDoc.AppHash) == 0 {
		return fmt.Errorf("AppHash is required when restoring chain")
	}

	reader, err := dump.NewFileReader(restoreFile)
	if err != nil {
		return err
	}

	err = dump.Load(reader, kern.State)
	if err != nil {
		return err
	}

	if !bytes.Equal(kern.State.Hash(), kern.Blockchain.GenesisDoc().AppHash) {
		return fmt.Errorf("restore produced a different apphash expect 0x%x got 0x%x",
			kern.Blockchain.GenesisDoc().AppHash, kern.State.Hash())
	}
	err = kern.Blockchain.CommitWithAppHash(kern.State.Hash())
	if err != nil {
		return fmt.Errorf("unable to commit %v", err)
	}

	kern.Logger.InfoMsg("State restore successful",
		"state_hash", kern.State.Hash())
	return nil
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1444. Elephpotamus Time limit: 0.5 second Memory limit: 64 MB Harry Potter is taking an examination in Care for Magical Creatures. His task is to feed a dwarf elephpotamus. Harry remembers that elephpotamuses are very straightforward and imperturbable. In fact, they are so straightforward that always move along a straight line and they are so imperturbable that only move when attracted by something really tasty. In addition, if an elephpotamus stumbles into a chain of its own footprints, it falls into a stupor and refuses to go anywhere. According to Hagrid, elephpotamuses usually get back home moving along their footprints. This is why they never cross them, otherwise they may get lost. When an elephpotamus sees its footprints, it tries to remember in detail all its movements since leaving home (this is also the reason why they move along straight lines only, this way it is easier to memorize). Basing on this information, the animal calculates in which direction its burrow is situated, then turns and goes straight to it. It takes some (rather large) time for an elephpotamus to perform these calculations. And what some ignoramuses recognize as a stupor is in fact a demonstration of outstanding calculating abilities of this wonderful, though a bit slow-witted creature. Elephpotamuses' favorite dainty is elephant pumpkins, and some of such pumpkins grow on the lawn where Harry is to take his exam. At the start of the exam, Hagrid will drag the elephpotamus to one of the pumpkins. Having fed the animal with a pumpkin, Harry can direct it to any of the remaining pumpkins. In order to pass the exam, Harry must lead the elephpotamus so that it eats as many pumpkins as possible before it comes across its footprints. Input The first input line contains the number of pumpkins on the lawn N (3 ≤ N ≤ 30000). The pumpkins are numbered from 1 to N, the number one being assigned to the pumpkin to which the animal is brought at the start of the trial. In the next N lines, the coordinates of the pumpkins are given in the order corresponding to their numbers. All the coordinates are integers in the range from −1000 to 1000. It is guaranteed that there are no two pumpkins at the same location and there is no straight line passing through all the pumpkins. Output In the first line write the maximal number K of pumpkins that can be fed to the elephpotamus. In the next K lines, output the order in which the animal will eat them, giving one number in a line. The first number in this sequence must always be 1.写一段Java完成此目的
最新发布
06-03
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值