Skip to content

Commit

Permalink
Merge pull request #1464 from dedis/block_size
Browse files Browse the repository at this point in the history
Add a per-ledger block-size limit
  • Loading branch information
ineiti committed Sep 12, 2018
2 parents 9e5db7a + e0fdf12 commit efbc02c
Show file tree
Hide file tree
Showing 30 changed files with 1,221 additions and 298 deletions.
10 changes: 10 additions & 0 deletions eventlog/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,3 +449,13 @@ func (s *Service) checkBuckets(inst omniledger.InstanceID, id skipchain.SkipBloc
}
return nil
}

// waitForBlock is for use in tests; it will sleep long enough to be sure that
// a block has been created.
func (s *Service) waitForBlock(scID skipchain.SkipBlockID) {
dur, _, err := s.omni.LoadBlockInfo(scID)
if err != nil {
panic(err.Error())
}
time.Sleep(5 * dur)
}
11 changes: 0 additions & 11 deletions eventlog/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"time"

omniledger "github.com/dedis/cothority/omniledger/service"
"github.com/dedis/cothority/skipchain"
"github.com/dedis/onet"
"github.com/dedis/onet/log"
"github.com/dedis/protobuf"
Expand Down Expand Up @@ -34,16 +33,6 @@ type Service struct {

const defaultBlockInterval = 5 * time.Second

// waitForBlock is for use in tests; it will sleep long enough to be sure that
// a block has been created.
func (s *Service) waitForBlock(scID skipchain.SkipBlockID) {
dur, err := s.omni.LoadBlockInterval(scID)
if err != nil {
panic(err.Error())
}
time.Sleep(5 * dur)
}

// This should be a const, but we want to be able to hack it from tests.
var searchMax = 10000

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
public class Config {
private Duration blockInterval;
private int maxBlockSize;

/**
* This instantiates a new configuration to be used in the omniledger constructor.
Expand All @@ -36,6 +37,10 @@ public Config(byte[] buf) throws CothorityCommunicationException {
try {
OmniLedgerProto.ChainConfig config = OmniLedgerProto.ChainConfig.parseFrom(buf);
this.blockInterval = Duration.of(config.getBlockinterval(), NANOS);
if (! config.hasMaxblocksize()) {
throw new RuntimeException("no max block size");
}
this.maxBlockSize = config.getMaxblocksize();
} catch (InvalidProtocolBufferException e) {
throw new CothorityCommunicationException(e);
}
Expand All @@ -48,12 +53,23 @@ public Duration getBlockInterval(){
return blockInterval;
}

public int getMaxBlockSize() {
return maxBlockSize;
}

// There is no setter for maxBlockSize right now because we do not expect java clients
// to need to adjust this. Modifying the block size via a transaction is tested/demoed in Go in
// TestService_SetConfig.
//public void setMaxBlockSize(int maxBlockSize) {
//}

/**
* @return the protobuf representation of the configuration.
*/
public OmniLedgerProto.ChainConfig toProto(){
OmniLedgerProto.ChainConfig.Builder b = OmniLedgerProto.ChainConfig.newBuilder();
b.setBlockinterval(blockInterval.get(NANOS));
b.setMaxblocksize(maxBlockSize);
return b.build();
}

Expand All @@ -62,6 +78,6 @@ public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Config config = (Config) o;
return blockInterval.equals(config.blockInterval);
return blockInterval.equals(config.blockInterval) && maxBlockSize == config.maxBlockSize;
}
}
42 changes: 33 additions & 9 deletions external/java/src/main/java/ch/epfl/dedis/proto/Calypso.java

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

0 comments on commit efbc02c

Please sign in to comment.